1、定时器重置
示例:
package main import ( "fmt" "time" ) func main() { timer := time.NewTimer(3 * time.Second) ok := timer.Reset(1 * time.Second) //重新设置为1s fmt.Println("ok = ", ok) <-timer.C fmt.Println("时间到") }
执行结果:
ok = true 时间到
1、定时器重置
示例:
package main import ( "fmt" "time" ) func main() { timer := time.NewTimer(3 * time.Second) ok := timer.Reset(1 * time.Second) //重新设置为1s fmt.Println("ok = ", ok) <-timer.C fmt.Println("时间到") }
执行结果:
ok = true 时间到
转载于:https://www.cnblogs.com/nulige/p/10288242.html