0PricingLogin
Go Academy · Lesson

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

  1. Time-Based Scheduling
  2. The robfig/cron Library
  3. Tickers for Intervals
  4. Graceful Job Shutdown
← Back to Go Academy