proposal: time: add API to retrieve next trigger time for Timer and Ticker #66680
Labels
Proposal
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
Proposal Details
The Go time package's Timer and Ticker are fundamental for scheduling future events. However, there's no straightforward way to query their next trigger time.
Currently, developers must resort to indirect methods to estimate the next trigger time. For example:
Estimating the next trigger time for Timer or Ticker is cumbersome and requires the context of their creation. For example, in a function that accepts only a Timer, the absence of creation context complicates accessing the next trigger time, hindering straightforward implementation and usage.
Internally, both Timer and Ticker leverage a structure similar to runtimeTimer, which already contains timing information such as when and nextwhen. This suggests that the necessary data for determining the next trigger time is already being tracked.
Proposal:
Introduce a method, NextTriggerTime(), (or any other aptly named method) be in Timer and Ticker, to expose the next trigger time. Given the internal tracking within runtimeTimer, this addition should be straightforward to implement and maintain.
Example usage:
The suggestion to use a method to obtain this information aims to ensure the integrity of the Timer/Ticker's own structural encapsulation and to avoid triggering concurrency access conflicts.
The text was updated successfully, but these errors were encountered: