timer and ticker

Go time values that deliver on a channel later: a timer fires once after a duration, a ticker fires repeatedly at an interval.

In more detail

time.After(d) is a one-shot timer channel, handy in a select for a timeout. A ticker suits periodic checks. Stop tickers and timers when you are done so they release resources; a context is often clearer for cancelling a whole request.

Example

ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()

Related terms

Taught in

References