-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.go
55 lines (44 loc) · 1.16 KB
/
timer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
return defaultWheelShard.After(d)
}
func Sleep(d time.Duration) {
//defaultWheel.Sleep(d)
defaultWheelShard.Sleep(d)
}
func AfterFunc(d time.Duration, f func()) *Timer {
//return defaultWheel.AfterFunc(d, f)
return defaultWheelShard.AfterFunc(d, f)
}
func NewTimer(d time.Duration) *Timer {
//return defaultWheel.NewTimer(d)
return defaultWheelShard.NewTimer(d)
}
func (t *Timer) Reset(d time.Duration) bool {
//return t.r.w.resetTimer(t.r, d, 0)
return t.r.ResetTimer(d, 0)
}
func (t *Timer) Stop() bool {
//return t.r.w.delTimer(t.r)
return t.r.Stop()
}
func (t *Timer) Release() {
//t.r.w.releaseTimer(t.r)
t.r.Release()
}
// 需要传入callback的接口,应该用NewWheelTimerFunc 接口, 而不是NewTimerFunc
func NewTimerFunc(d time.Duration, callback func(time.Time, ...interface{}), arg ...interface{}) *Timer {
//return defaultWheel.NewTimerFunc(d, callback, arg...)
return defaultWheelShard.NewTimerFunc(d, callback, arg...)
}
func (t *Timer) Info() string {
return t.r.Info()
}