diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2015-10-23 14:56:01 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2015-10-23 14:56:01 +0300 |
commit | 40e775dce5833385cc180b9b47d2ce60ffcaba15 (patch) | |
tree | 2d8da4567a1c237cb6e3f0dd7879a81becad6549 /timer.go | |
parent | Properly implement request read timeout via SetReadDeadline(). Implement resp... (diff) | |
download | fasthttp-40e775dce5833385cc180b9b47d2ce60ffcaba15.tar.gz fasthttp-40e775dce5833385cc180b9b47d2ce60ffcaba15.tar.bz2 fasthttp-40e775dce5833385cc180b9b47d2ce60ffcaba15.zip |
Added TimeoutHandler
Diffstat (limited to 'timer.go')
-rw-r--r-- | timer.go | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -1,26 +1,20 @@ package fasthttp import ( - "sync" "time" ) -var timerPool sync.Pool - -func acquireTimer(timeout time.Duration) *time.Timer { - tv := timerPool.Get() - if tv == nil { +func initTimer(t *time.Timer, timeout time.Duration) *time.Timer { + if t == nil { return time.NewTimer(timeout) } - - t := tv.(*time.Timer) if t.Reset(timeout) { - panic("BUG: Active timer trapped into AcquireTimer()") + panic("BUG: active timer trapped into initTimer()") } return t } -func releaseTimer(t *time.Timer) { +func stopTimer(t *time.Timer) { if !t.Stop() { // Collect possibly added time from the channel // if timer has been stopped and nobody collected its' value. @@ -29,6 +23,4 @@ func releaseTimer(t *time.Timer) { default: } } - - timerPool.Put(t) } |