Tickers for Intervals
Repeat at fixed rates.
Repeating at a Fixed Rate
When you simply need to do something every N seconds, a Ticker is the right tool. Unlike a sleep loop, it fires on a steady cadence and does not drift with work time.
Creating a Ticker
time.NewTicker(d) returns a Ticker whose channel C receives the current time every d.
ticker := time.NewTicker(time.Second)
defer ticker.Stop()All lessons in this course
- Time-Based Scheduling
- The robfig/cron Library
- Tickers for Intervals
- Graceful Job Shutdown