-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathsystem.go
72 lines (55 loc) · 1.53 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package clock
import "time"
type systemTime struct{}
func (st *systemTime) Now() time.Time {
return time.Now()
}
func (st *systemTime) Sleep(d time.Duration) {
time.Sleep(d)
}
func (st *systemTime) After(d time.Duration) <-chan time.Time {
return time.After(d)
}
type systemTimer struct {
t *time.Timer
}
func (st *systemTime) NewTimer(d time.Duration) Timer {
t := time.NewTimer(d)
return &systemTimer{t}
}
func (st *systemTime) AfterFunc(d time.Duration, f func()) Timer {
t := time.AfterFunc(d, f)
return &systemTimer{t}
}
func (t *systemTimer) C() <-chan time.Time {
return t.t.C
}
func (t *systemTimer) Stop() bool {
return t.t.Stop()
}
func (t *systemTimer) Reset(d time.Duration) bool {
return t.t.Reset(d)
}
type systemTicker struct {
t *time.Ticker
}
func (t *systemTicker) C() <-chan time.Time {
return t.t.C
}
func (t *systemTicker) Stop() {
t.t.Stop()
}
func (st *systemTime) NewTicker(d time.Duration) Ticker {
t := time.NewTicker(d)
return &systemTicker{t}
}
// Tick creates a new Ticker and returns ticker channel.
// Use sparingly or in unit tests as this potentially generates a resource leak.
// https://staticcheck.io/docs/checks#SA1015
func (st *systemTime) Tick(d time.Duration) <-chan time.Time {
//nolint: staticcheck // FIXME: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here
return time.Tick(d)
}
func (st *systemTime) Wait4Scheduled(count int, timeout time.Duration) bool {
panic("Not supported")
}