Is it possible to execute code at a noon everyday? The program is handling user input the rest of its run time but needs to run a function at noon to output some text. What is the most effective way to do this?
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- How to account for clock offsets in a distributed
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
相关文章
- Can I run a single test in a suite?
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- How to access value of first index of array in Go
- Embedded Interface
- Get POSIX epoch as system_clock::time_point
- How to represent an array with mixed types
- go tutorial select statement
So you need Interval Timer to run one function at noon everyday, you may use:
timer.AfterFunc()
ortime.Tick()
ortime.Sleep()
ortime.Ticker
first when program starts calculate time interval for start up time till first next noon and use some wait (e.g.
time.Sleep
or ...) then use24 * time.Hour
interval for the next interval.sample code using
time.Sleep
:and you may change main to this (or any thing you need):
using
timer.AfterFunc
:using
time.Ticker
:and see:
https://github.com/jasonlvhit/gocron
Golang - How to execute function at specific times
Golang: Implementing a cron / executing tasks at a specific time