-
Notifications
You must be signed in to change notification settings - Fork 1
/
real_clock.go
45 lines (33 loc) · 963 Bytes
/
real_clock.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
package glock
import "time"
type realClock struct{}
var _ Clock = &realClock{}
// NewRealClock returns a Clock whose implementation falls back to the
// methods available in the time package.
func NewRealClock() Clock {
return &realClock{}
}
func (c *realClock) Now() time.Time {
return time.Now()
}
func (c *realClock) After(duration time.Duration) <-chan time.Time {
return time.After(duration)
}
func (c *realClock) Sleep(duration time.Duration) {
time.Sleep(duration)
}
func (c *realClock) Since(t time.Time) time.Duration {
return time.Since(t)
}
func (c *realClock) Until(t time.Time) time.Duration {
return time.Until(t)
}
func (c *realClock) NewTicker(duration time.Duration) Ticker {
return NewRealTicker(duration)
}
func (c *realClock) NewTimer(duration time.Duration) Timer {
return NewRealTimer(duration)
}
func (c *realClock) AfterFunc(duration time.Duration, f func()) Timer {
return newRealTimer(time.AfterFunc(duration, f))
}