We break down how to wait in Go “for a time event” rather than just “pause”: a one-shot timer via
time.After and regular ticks via
time.NewTicker. In practice, we will see that both tools return a time channel (
<-
chan
time.Time), learn to read an event with the
<- operator, properly stop a ticker via
defer
ticker
.
Stop
(), and discuss common mistakes (forgot to read from the channel, did not stop the ticker, expected perfect accuracy, confused a timeout with cancellation via
context).