You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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.
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
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:
The text was updated successfully, but these errors were encountered: