mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 20:33:08 +00:00
Update timeout.go
Co-Authored-By: kiyon <kiyonlin@163.com>
This commit is contained in:
parent
aed889e828
commit
1129a85058
@ -8,29 +8,6 @@ import (
|
||||
|
||||
// Timeout wraps a handler and aborts the process of the handler if the timeout is reached
|
||||
func Timeout(handler fiber.Handler, timeout time.Duration) fiber.Handler {
|
||||
// fHandler := func(fctx *fasthttp.RequestCtx) {
|
||||
// // Emulate long-running task, which touches ctx.
|
||||
// doneCh := make(chan struct{})
|
||||
// go func() {
|
||||
// workDuration := time.Millisecond * time.Duration(rand.Intn(2000))
|
||||
// time.Sleep(workDuration)
|
||||
|
||||
// fmt.Fprintf(fctx, "ctx has been accessed by long-running task\n")
|
||||
// fmt.Fprintf(fctx, "The reuqestHandler may be finished by this time.\n")
|
||||
|
||||
// close(doneCh)
|
||||
// }()
|
||||
|
||||
// select {
|
||||
// case <-doneCh:
|
||||
// case <-time.After(timeout):
|
||||
// fctx.TimeoutError("Timeout!")
|
||||
// }
|
||||
// }
|
||||
// return func(ctx *fiber.Ctx) {
|
||||
// fHandler(ctx.Fasthttp)
|
||||
// }
|
||||
|
||||
if timeout <= 0 {
|
||||
return handler
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user