-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
system.go
50 lines (36 loc) · 878 Bytes
/
system.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 clock
import "time"
type systemTimer struct {
timer *time.Timer
}
func (s systemTimer) C() <-chan time.Time {
return s.timer.C
}
func (s systemTimer) Reset(d time.Duration) {
s.timer.Reset(d)
}
func (s systemTimer) Stop() bool {
return s.timer.Stop()
}
type systemTicker struct {
ticker *time.Ticker
}
func (s systemTicker) C() <-chan time.Time {
return s.ticker.C
}
func (s systemTicker) Stop() {
s.ticker.Stop()
}
func (s systemTicker) Reset(d time.Duration) {
s.ticker.Reset(d)
}
type systemClock struct{}
func (clock systemClock) Ticker(d time.Duration) Ticker {
return systemTicker{ticker: time.NewTicker(d)}
}
func (systemClock) Timer(d time.Duration) Timer {
return systemTimer{timer: time.NewTimer(d)}
}
func (systemClock) Now() time.Time { return time.Now() }
// System Clock.
var System Clock = systemClock{} // nolint:gochecknoglobals