siddontang.golib/timer/sleep.go

35 lines
512 B
Go
Raw Normal View History

2014-04-15 16:36:20 +08:00
package timer
import (
"time"
)
type Timer struct {
C <-chan time.Time
r *timer
}
func After(d time.Duration) <-chan time.Time {
return defaultWheel.After(d)
}
func Sleep(d time.Duration) {
defaultWheel.Sleep(d)
}
func AfterFunc(d time.Duration, f func()) *Timer {
return defaultWheel.AfterFunc(d, f)
}
func NewTimer(d time.Duration) *Timer {
return defaultWheel.NewTimer(d)
}
func (t *Timer) Reset(d time.Duration) {
t.r.w.resetTimer(t.r, d, 0)
}
func (t *Timer) Stop() {
t.r.w.delTimer(t.r)
}