论golang Timer Reset方法使用的正确姿势

bigwhite ·
更多评论
``` func main(){ //example4.go c:=make(chan bool,10) exit:=make(chan bool) go func() { for j:=0;j<5;j++ { for i := 0; i < 3; i++ { c <- false time.Sleep(time.Second * 1) } time.Sleep(5*time.Second) } }() go func() { time.Sleep(120*time.Second) exit<-false }() var icount int timer := time.NewTimer(time.Second * 3) for { select { case b:=<-c: icount++ fmt.Println(time.Now(), ":recv===>",b) timer.Reset(time.Second * 3) case <-timer.C: fmt.Println(time.Now(), ":recv total:",icount) //当c管道阻塞时,仅打印接收数据次数 case <-exit: fmt.Println("退出") //当c管道阻塞时,仅打印接收数据次数 return } } } ```
#1