-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: add Ticker.Reset #33184
Comments
It seems reasonable to be able to change the duration on a ticker.
The second seems defensible to me and useful in code that is doing something like:
In general, if the Reset is happening separate from the channel receive, you'd want to do t.Stop, then synchronize with the receiver so it knows to expect a new duration, then t.Reset. But the pattern above does not need that because the receiver and the Reset caller are the same, and that seems likely to be common. So I would lean toward option 2. Thoughts? |
@rsc
This way developers can control their own startup time,later added api Reset,using like this:
But this does have a situation where stopTimer returns an error,do you have a better solution? |
Given the two options I mentioned above, it seems like "the ticker is not stopped, first stop it and drain any existing value from the channel" is the much less error-prone API. If you don't want that, you can of course stop the ticker yourself first. With that clarification, this seems like a likely accept. |
No change in consensus, so accepted. |
Change https://golang.org/cl/217362 mentions this issue: |
Change https://golang.org/cl/220638 mentions this issue: |
CL reverted due to test failures, so reopening. |
This reverts CL 217362 (6e5652b.) Reason for revert: Causing failures on arm64 bots. See #33184 for more info Change-Id: I72ba40047e4138767d95aaa68842893c3508c52f Reviewed-on: https://go-review.googlesource.com/c/go/+/220638 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Example failure on arm64: https://build.golang.org/log/518de921e4d47fb5130e0f9f969437fdab9d872e Relevant snippet:
|
Change https://golang.org/cl/220424 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes.
What operating system and processor architecture are you using (
go env
)?linux amd64
What did you do?
I added the api reset function.
What did you expect to see?
I hope that the proposal will take effect,because sometimes we need to adjust the time dynamically.
This is not a problem,this is just a suggestion.
Please read the following.thanks.
api:
The text was updated successfully, but these errors were encountered: