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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time: Timer.Reset documentation not accurate for AfterFunc timers #28100
Comments
The code makes it pretty clear a value is never sent on a channel, but here's a playground example: https://play.golang.org/p/2OSQiHS4Zt5 Code: func NewTimer(d Duration) *Timer {
c := make(chan Time, 1)
t := &Timer{
C: c,
r: runtimeTimer{
when: when(d),
f: sendTime, // <<<<<<<<<<<<<<<<<<
arg: c,
},
}
startTimer(&t.r)
return t
} vs func AfterFunc(d Duration, f func()) *Timer {
t := &Timer{
r: runtimeTimer{
when: when(d),
f: goFunc, // <<<<<<<<<<<<<<<<<<
arg: f,
},
}
startTimer(&t.r)
return t
} |
Context: review comments on https://go-review.googlesource.com/c/go/+/137335 |
Agreed. My parsing of the However, it'd be great to be explicit and more accurate. |
If |
What about changing:
to:
? |
If we're going to change something we may as well explain what happens with a timer created by |
Change https://golang.org/cl/285632 mentions this issue: |
https://golang.org/pkg/time/#Timer.Reset says:
And proceeds to give an example of proper usage of Reset.
But a Timer created by AfterFunc never sends on the channel.
We should probably say something about AfterFunc in the Timer.Reset docs.
/cc @dmitshur @ianlancetaylor
The text was updated successfully, but these errors were encountered: