@@ -9,14 +9,14 @@ import (
9
9
// This is usually the system time, but can be something else for unit tests.
10
10
type TimeProvider func () time.Time
11
11
12
- // The default system time provider
12
+ // SysTimeProvider is the default system time provider
13
13
var SysTimeProvider = func () time.Time { return time .Now () }
14
14
15
- // A SleepConsumer sleeps the given amount of time.
15
+ // SleepConsumer sleeps the given amount of time.
16
16
// This is usually the time.Sleep method, but can be something else for unit tests.
17
17
type SleepConsumer func (time.Duration )
18
18
19
- // The default system sleep consumer
19
+ // SysSleepConsumer is the default system sleep consumer
20
20
var SysSleepConsumer = func (d time.Duration ) { time .Sleep (d ) }
21
21
22
22
// A Timer can be started and stopped. It will start at zero and count up, while running.
@@ -31,7 +31,7 @@ type Timer struct {
31
31
continueChan chan struct {}
32
32
}
33
33
34
- // Create a new stopped timer based on system time
34
+ // NewTimer creates a new stopped timer based on system time
35
35
func NewTimer () Timer {
36
36
return Timer {
37
37
time .Now (),
@@ -43,19 +43,20 @@ func NewTimer() Timer {
43
43
make (chan struct {})}
44
44
}
45
45
46
- // Is timer currently running?
46
+ // Running returns if timer is currently running
47
47
func (t * Timer ) Running () bool {
48
48
return t .running
49
49
}
50
50
51
- // Return the elapsed time of this timer
51
+ // Elapsed returns the elapsed time of this timer
52
52
func (t * Timer ) Elapsed () time.Duration {
53
53
if t .running {
54
54
return t .offset + t .TimeProvider ().Sub (t .start )
55
55
}
56
56
return t .offset
57
57
}
58
58
59
+ // Delta returns the time since last call to Delta
59
60
func (t * Timer ) Delta () time.Duration {
60
61
elapsed := t .Elapsed ()
61
62
delta := elapsed - t .deltaOffset
@@ -89,7 +90,7 @@ func (t *Timer) Stop() error {
89
90
return nil
90
91
}
91
92
92
- // Wait until the internal timer duration is reached.
93
+ // WaitTill waits until the internal timer duration is reached.
93
94
func (t * Timer ) WaitTill (duration time.Duration ) error {
94
95
if ! t .running {
95
96
select {
@@ -105,7 +106,7 @@ func (t *Timer) WaitTill(duration time.Duration) error {
105
106
return nil
106
107
}
107
108
108
- // Wait until the internal timer has reached the next full second
109
+ // WaitTillNextFullSecond waits until the internal timer has reached the next full second
109
110
func (t * Timer ) WaitTillNextFullSecond () error {
110
111
elapsed := t .Elapsed ()
111
112
nextDuration := elapsed .Truncate (time .Second ) + time .Second
0 commit comments