-
Notifications
You must be signed in to change notification settings - Fork 65
/
timewheel.go
50 lines (38 loc) · 971 Bytes
/
timewheel.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
package timewheel
import (
"time"
)
var (
DefaultTimeWheel, _ = NewTimeWheel(time.Second, 120)
)
func init() {
DefaultTimeWheel.Start()
}
func ResetDefaultTimeWheel(tw *TimeWheel) {
tw.Start()
DefaultTimeWheel = tw
}
func Add(delay time.Duration, callback func()) *Task {
return DefaultTimeWheel.Add(delay, callback)
}
func AddCron(delay time.Duration, callback func()) *Task {
return DefaultTimeWheel.AddCron(delay, callback)
}
func Remove(task *Task) error {
return DefaultTimeWheel.Remove(task)
}
func NewTimer(delay time.Duration) *Timer {
return DefaultTimeWheel.NewTimer(delay)
}
func NewTicker(delay time.Duration) *Ticker {
return DefaultTimeWheel.NewTicker(delay)
}
func AfterFunc(delay time.Duration, callback func()) *Timer {
return DefaultTimeWheel.AfterFunc(delay, callback)
}
func After(delay time.Duration) <-chan time.Time {
return DefaultTimeWheel.After(delay)
}
func Sleep(delay time.Duration) {
DefaultTimeWheel.Sleep(delay)
}