81
Go Tickers
Go Tickers are used when we want to some work at regular interval of time. Tickers can be stopped like timers using the Stop() method.
The NewTicker() method returns a new Ticker having a channel which send the time according to the duration argument. The duration must be larger than zero, if not, the ticker will panic.
The Tick() is a wrapper for NewTicker which provides access to the ticking channel. The Tick() method is useful for clients who don’t want to shutdown the Ticker.
Go Tickers Example
Output:
Tick at 2017-10-07 17:26:35.946279716 +0530 IST m=+0.101345812 Tick at 2017-10-07 17:26:36.046371811 +0530 IST m=+0.201437907 Tick at 2017-10-07 17:26:36.146417657 +0530 IST m=+0.301483753 Tick at 2017-10-07 17:26:36.24851386 +0530 IST m=+0.403579956 Tick at 2017-10-07 17:26:36.346476978 +0530 IST m=+0.501543074 Ticker stopped
Go Ticker Example 2
Output:
2017/10/07 18:15:15 A: Let's have fun: B : Okay! 2017/10/07 18:15:17 A: Let's have fun: B : Okay! 2017/10/07 18:15:19 A: Let's have fun: B : Okay! 2017/10/07 18:15:21 A: Let's have fun: B : Okay! 2017/10/07 18:15:23 A: Let's have fun: B : Okay! 2017/10/07 18:15:25 A: Let's have fun: B : Okay!
Next TopicGo File I/O