-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
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