Go by Example - Tickers
Go by Example
Go is an open source programming language designed for building simple, fast, and reliable software.
Go by Example is a hands-on introduction to Go using annotated example programs. Check out the first example or browse the full list below.
Go by Example: Tickers
Timer
是当你想要在未来某个时间只执行一次某个事件时使用,而ticker
可以用来以一定时间间隔重复执行一个事件。
1 | package main |
1 | tashuo:golang ta_shuo$ go run ticker.go |
在执行1600毫秒被停止时Ticker 500毫秒的间隔应该已经重复执行了三次