Files
fasthttp/timer.go
T
Aliaksandr Valialkin 40e775dce5 Added TimeoutHandler
2015-10-23 14:56:01 +03:00

27 lines
455 B
Go

package fasthttp
import (
"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:
}
}
}