Skip to content

Commit 9c1a6a2

Browse files
authored
feat: add docstrings to mock timer and ticker methods and structs (coder#13658)
1 parent 46e1c36 commit 9c1a6a2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clock/ticker.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package clock
22

33
import "time"
44

5+
// A Ticker holds a channel that delivers “ticks” of a clock at intervals.
56
type Ticker struct {
67
C <-chan time.Time
78
//nolint: revive
@@ -33,6 +34,9 @@ func (t *Ticker) next() time.Time {
3334
return t.nxt
3435
}
3536

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".
3640
func (t *Ticker) Stop(tags ...string) {
3741
if t.ticker != nil {
3842
t.ticker.Stop()
@@ -47,6 +51,9 @@ func (t *Ticker) Stop(tags ...string) {
4751
t.stopped = true
4852
}
4953

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.
5057
func (t *Ticker) Reset(d time.Duration, tags ...string) {
5158
if t.ticker != nil {
5259
t.ticker.Reset(d)

clock/timer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package clock
22

33
import "time"
44

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.
58
type Timer struct {
69
C <-chan time.Time
710
//nolint: revive
@@ -26,6 +29,11 @@ func (t *Timer) next() time.Time {
2629
return t.nxt
2730
}
2831

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.
2937
func (t *Timer) Stop(tags ...string) bool {
3038
if t.timer != nil {
3139
return t.timer.Stop()
@@ -40,6 +48,10 @@ func (t *Timer) Stop(tags ...string) bool {
4048
return result
4149
}
4250

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.
4355
func (t *Timer) Reset(d time.Duration, tags ...string) bool {
4456
if t.timer != nil {
4557
return t.timer.Reset(d)

0 commit comments

Comments
 (0)