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: NewTickerStartingAt and RuntimeStarted #43503

Open
pschou opened this issue Jan 5, 2021 · 4 comments
Open

proposal: time: NewTickerStartingAt and RuntimeStarted #43503

pschou opened this issue Jan 5, 2021 · 4 comments

Comments

@pschou
Copy link

pschou commented Jan 5, 2021

Proposed new functions for NewTickerStartingAt and RuntimeStarted in time

NewTickerStartingAt - The function NewTicker has been limiting users as often I need a NewTicker that starts ticking at a specific time. I find many times I was wrapping this timer call in an anonymous function with sleep then a NewTicker. To avoid this redundancy for others and myself, I'd like to expose the interface to the underlying timer interface with both inputs: period duration and start time for the initial tick. For example; an initial ticket the fires immediately use NewTickerStartingAt(duration, time.Now()). If the proposed time is in the past it immediately fires and then syncs up on that interval. Another example: the duration is set to a minute, and then starting at a time is also on a minute mark, the result is ticked at the minute. Times passing over a leap second is a known limitation, but this is also experienced by NewTicker

RuntimeStarted - is useful to have as a way of looking up the runtime. I know something similar can be created by storing this value via an init() function, but having a static value in the time library can be useful in many places. Such as metrics. Efficiency is achieved by storing the structure values in start_ local variables so subsequent calls will retrieve the exact same time.

Proposal:
https://go-review.googlesource.com/c/proposal/+/281453/2

View pull request: here:
#43488

View pull request discussion here:
https://go-review.googlesource.com/c/go/+/281332

I need a function to start a timer at an arbitrary time. This is related to and also resolves issues:
#41885
#17601

@davecheney
Copy link
Contributor

Thank you for raising this issue. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@pschou
Copy link
Author

pschou commented Jan 5, 2021

Yes, thank you, I have a proposal here that I want to link to this

https://go-review.googlesource.com/c/proposal/+/281453/2

@pschou pschou changed the title Need a NewTicker to start at an arbitrary time and a way to get the process start time time: Need a NewTicker to start at an arbitrary time and a way to get the process start time Jan 5, 2021
@ianlancetaylor ianlancetaylor changed the title time: Need a NewTicker to start at an arbitrary time and a way to get the process start time proposal: time: NewTickerStartingAt and RuntimeStarted Jan 5, 2021
@gopherbot gopherbot added this to the Proposal milestone Jan 5, 2021
@ianlancetaylor
Copy link
Contributor

It will be easier to understand this proposal if you can update the initial comment to provide a brief description of the functions you propose adding. Thanks.

@gopherbot
Copy link

Change https://golang.org/cl/281332 mentions this issue: design: NewTickerStartingAt doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants