February 2018
Intermediate to advanced
340 pages
9h 43m
English
The Ticker holds the C channel which delivers the periodical ticks. The instance is created with a given interval between ticks. The interval is defined by the time.Duration value.
The code which is intended to be executed periodically is executed in the goroutine in an infinite loop. The reading from the Ticker channel blocks the loop until the tick is delivered.
Note that once the Ticker is stopped by calling the Stop method, the C channel is not closed, it just stops delivering the ticks. For this reason, the preceding code contains the select construct where the stop channel can deliver the stop signal. This way, a graceful shutdown can be done.
Read now
Unlock full access