Go by Example - Timers
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: Timers
我们经常希望golang代码在未来某个时间点执行或者以一定的时间间隔重复执行,golang内置的timer
和ticker
功能可以轻松实现这两种工作。
1 | package main |
1 | tashuo:golang ta_shuo$ go run timer.go |
第一个timer会在2秒后过期,但是第二个timer在过期前被Stop,所以没有过期