-
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
proposal: time: add a channel to time.Ticker to detect stopped tickers #35643
Comments
Seems that you could define your own type that uses time.Ticker to implement the semantics you want. |
Adding a channel to the I don't think your issue citations refer to your suggestion. Those issues are all suggesting that when a |
Good point. I thought a channel of type As to the citations, my bad. I meant to say that this proposal would be an alternative solution to cited issues. |
It is the job of the standard library to provide strong, robust building blocks like time.Ticker. This does not seem to come up often enough to be worth the added complexity and runtime cost of a second channel in the ticker interface for every user. If your use case really needs to know when the ticker has been stopped, then as has been pointed out it is easy to write and use a wrapper that provides that extra functionality. |
Given that this is very easy to do anyhow and not possible to do in time.Ticker without forcing overhead on everyone, this seems like a likely decline. Leaving open for a week for final comments. |
Good with me. I didn't consider the the size of the channel when I submitted this proposal. |
No change in consensus, so declining. |
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
)?What did you do?
https://play.golang.org/p/e5B2M9b1rWc
What did you expect to see?
I would like a simple way to detect a stopped ticker.
I know it's easily implemented using a second channel: https://play.golang.org/p/r36mEd85_6S
However, In a service where tickers are created and stopped frequently, it's not elegant (to say the least) to create a second channel with each ticker to avoid memory leaks when tickers are stopped (https://play.golang.org/p/lGfYd7Kq3kH).
I have read the discussion in #2650 and understand it is preferred to keep current semantics.
However, something like the following would make things easier without breaking existing semantics:
The text was updated successfully, but these errors were encountered: