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

feat: add docstrings to mock timer and ticker methods and structs#13658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionsclock/ticker.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package clock

import "time"

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

// Stop turns off a ticker. After Stop, no more ticks will be sent. Stop does
// not close the channel, to prevent a concurrent goroutine reading from the
// channel from seeing an erroneous "tick".
func (t *Ticker) Stop(tags ...string) {
if t.ticker != nil {
t.ticker.Stop()
Expand All@@ -47,6 +51,9 @@ func (t *Ticker) Stop(tags ...string) {
t.stopped = true
}

// Reset stops a ticker and resets its period to the specified duration. The
// next tick will arrive after the new period elapses. The duration d must be
// greater than zero; if not, Reset will panic.
func (t *Ticker) Reset(d time.Duration, tags ...string) {
if t.ticker != nil {
t.ticker.Reset(d)
Expand Down
12 changes: 12 additions & 0 deletionsclock/timer.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ package clock

import"time"

// The Timer type represents a single event. When the Timer expires, the current time will be sent
// on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or
// AfterFunc.
typeTimerstruct {
C<-chan time.Time
//nolint: revive
Expand All@@ -26,6 +29,11 @@ func (t *Timer) next() time.Time {
returnt.nxt
}

// Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the
// timer has already expired or been stopped. Stop does not close the channel, to prevent a read
// from the channel succeeding incorrectly.
//
// See https://pkg.go.dev/time#Timer.Stop for more information.
func (t*Timer)Stop(tags...string)bool {
ift.timer!=nil {
returnt.timer.Stop()
Expand All@@ -40,6 +48,10 @@ func (t *Timer) Stop(tags ...string) bool {
returnresult
}

// Reset changes the timer to expire after duration d. It returns true if the timer had been active,
// false if the timer had expired or been stopped.
//
// See https://pkg.go.dev/time#Timer.Reset for more information.
func (t*Timer)Reset(d time.Duration,tags...string)bool {
ift.timer!=nil {
returnt.timer.Reset(d)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp