go的定时器channel ,timer和ticker还是有点不同的
package main import ( // "fmt" "time" "log" ) func main() { d := time.Duration(time.Second) t := time.NewTicker(d) // t := time.NewTimer(d) defer t.Stop() for { <- t.C log.Println("timeout...") time.Sleep(time.Second*5) // need reset // t.Reset(time.Second*2) } }