Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit834f943

Browse files
committed
feat: add docstrings to mock timer and ticker methods and structs
1 parentefa2738 commit834f943

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
typeTickerstruct {
67
C<-chan time.Time
78
//nolint: revive
@@ -33,6 +34,9 @@ func (t *Ticker) next() time.Time {
3334
returnt.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
ift.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
ift.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
typeTimerstruct {
69
C<-chan time.Time
710
//nolint: revive
@@ -26,6 +29,11 @@ func (t *Timer) next() time.Time {
2629
returnt.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
ift.timer!=nil {
3139
returnt.timer.Stop()
@@ -40,6 +48,10 @@ func (t *Timer) Stop(tags ...string) bool {
4048
returnresult
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
ift.timer!=nil {
4557
returnt.timer.Reset(d)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp