replace zxq.co/ripple/hanayo
This commit is contained in:
44
vendor/github.com/valyala/fasthttp/timer.go
generated
vendored
Normal file
44
vendor/github.com/valyala/fasthttp/timer.go
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func initTimer(t *time.Timer, timeout time.Duration) *time.Timer {
|
||||
if t == nil {
|
||||
return time.NewTimer(timeout)
|
||||
}
|
||||
if t.Reset(timeout) {
|
||||
panic("BUG: active timer trapped into initTimer()")
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
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.
|
||||
select {
|
||||
case <-t.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func acquireTimer(timeout time.Duration) *time.Timer {
|
||||
v := timerPool.Get()
|
||||
if v == nil {
|
||||
return time.NewTimer(timeout)
|
||||
}
|
||||
t := v.(*time.Timer)
|
||||
initTimer(t, timeout)
|
||||
return t
|
||||
}
|
||||
|
||||
func releaseTimer(t *time.Timer) {
|
||||
stopTimer(t)
|
||||
timerPool.Put(t)
|
||||
}
|
||||
|
||||
var timerPool sync.Pool
|
Reference in New Issue
Block a user