Skip to content

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

@justincpresley

Description

@justincpresley

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions