Skip to content
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 Ticker functions to affect the next tick #55129

Closed
justincpresley opened this issue Sep 18, 2022 · 4 comments
Closed

proposal: time: add Ticker functions to affect the next tick #55129

justincpresley opened this issue Sep 18, 2022 · 4 comments

Comments

@justincpresley
Copy link

While it accomplishes the goal, I find the time.Ticker's API to be very limiting.
In many unique cases, you may want the functionality of a ticker but also want more control over when the next tick happens. One method to achieve this is to simply create a new Ticker. However, this becomes burdensome for the Garbage Collector if we are operating at the millisecond/nanosecond duration. It also is arguably inefficient for such a small feature especially if this is done for a larger project.

To help tackle this, I propose the following API:

// Sets the duration till the next tick happens.
// Ticker resumes the normal duration after the next tick.
(t *Ticker) Set(time.Duration)

// Skip immediately executes a tick.
(t *Ticker) Skip()

// Add adds time before the next tick happens.
(t *Ticker) Add(time.Duration)

// TimeLeft returns the duration of time till the next tick.
(t *Ticker) TimeLeft() time.Duration
@gopherbot gopherbot added this to the Proposal milestone Sep 18, 2022
@justincpresley justincpresley changed the title proposal: time: Add Ticker Functions to Affect the Next Tick proposal: time: add Ticker functions to affect the next tick Sep 18, 2022
@ianlancetaylor
Copy link
Contributor

The point of time.Ticker is that it tries to give a regular tick regardless of system delays and such. You seem to be describing a different kind of functionality. I think you could probably build what you want on top of time.Timer. That seems like a better direction than complicating time.Ticker.

@rsc
Copy link
Contributor

rsc commented Sep 28, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Oct 6, 2022

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Oct 12, 2022

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc closed this as completed Oct 12, 2022
@golang golang locked and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants