File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package clock
2
2
3
3
import "time"
4
4
5
+ // A Ticker holds a channel that delivers “ticks” of a clock at intervals.
5
6
type Ticker struct {
6
7
C <- chan time.Time
7
8
//nolint: revive
@@ -33,6 +34,9 @@ func (t *Ticker) next() time.Time {
33
34
return t .nxt
34
35
}
35
36
37
+ // Stop turns off a ticker. After Stop, no more ticks will be sent. Stop does
38
+ // not close the channel, to prevent a concurrent goroutine reading from the
39
+ // channel from seeing an erroneous "tick".
36
40
func (t * Ticker ) Stop (tags ... string ) {
37
41
if t .ticker != nil {
38
42
t .ticker .Stop ()
@@ -47,6 +51,9 @@ func (t *Ticker) Stop(tags ...string) {
47
51
t .stopped = true
48
52
}
49
53
54
+ // Reset stops a ticker and resets its period to the specified duration. The
55
+ // next tick will arrive after the new period elapses. The duration d must be
56
+ // greater than zero; if not, Reset will panic.
50
57
func (t * Ticker ) Reset (d time.Duration , tags ... string ) {
51
58
if t .ticker != nil {
52
59
t .ticker .Reset (d )
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ package clock
2
2
3
3
import "time"
4
4
5
+ // The Timer type represents a single event. When the Timer expires, the current time will be sent
6
+ // on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or
7
+ // AfterFunc.
5
8
type Timer struct {
6
9
C <- chan time.Time
7
10
//nolint: revive
@@ -26,6 +29,11 @@ func (t *Timer) next() time.Time {
26
29
return t .nxt
27
30
}
28
31
32
+ // Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the
33
+ // timer has already expired or been stopped. Stop does not close the channel, to prevent a read
34
+ // from the channel succeeding incorrectly.
35
+ //
36
+ // See https://pkg.go.dev/time#Timer.Stop for more information.
29
37
func (t * Timer ) Stop (tags ... string ) bool {
30
38
if t .timer != nil {
31
39
return t .timer .Stop ()
@@ -40,6 +48,10 @@ func (t *Timer) Stop(tags ...string) bool {
40
48
return result
41
49
}
42
50
51
+ // Reset changes the timer to expire after duration d. It returns true if the timer had been active,
52
+ // false if the timer had expired or been stopped.
53
+ //
54
+ // See https://pkg.go.dev/time#Timer.Reset for more information.
43
55
func (t * Timer ) Reset (d time.Duration , tags ... string ) bool {
44
56
if t .timer != nil {
45
57
return t .timer .Reset (d )
You can’t perform that action at this time.
0 commit comments