Source File
timer.go
Belonging Package
github.com/valyala/fasthttp
package fasthttpimport ()func initTimer( *time.Timer, time.Duration) *time.Timer {if == nil {return time.NewTimer()}if .Reset() {// developer sanity-checkpanic("BUG: active timer trapped into initTimer()")}return}func stopTimer( *time.Timer) {if !.Stop() {// Collect possibly added time from the channel// if timer has been stopped and nobody collected its value.select {case <-.C:default:}}}// AcquireTimer returns a time.Timer from the pool and updates it to// send the current time on its channel after at least timeout.//// The returned Timer may be returned to the pool with ReleaseTimer// when no longer needed. This allows reducing GC load.func ( time.Duration) *time.Timer {:= timerPool.Get()if == nil {return time.NewTimer()}:= .(*time.Timer)initTimer(, )return}// ReleaseTimer returns the time.Timer acquired via AcquireTimer to the pool// and prevents the Timer from firing.//// Do not access the released time.Timer or read from its channel otherwise// data races may occur.func ( *time.Timer) {stopTimer()timerPool.Put()}var timerPool sync.Pool
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |