Professional Documents
Culture Documents
Tickers
Tickers
package main
import (
"fmt"
"time"
)
func main() {
go func() {
for {
select {
case <-done:
return
case t := <-ticker.C:
fmt.Println("Tick at", t)
}
}
}()
When we run this program the ticker should tick 3 $ go run tickers.go
times before we stop it. Tick at 2012-09-23 11:29:56.487625 -0700 PDT
Tick at 2012-09-23 11:29:56.988063 -0700 PDT
Tick at 2012-09-23 11:29:57.488076 -0700 PDT
Ticker stopped