Go实例: Timers

Valentina ·
更新时间:2024-11-13
· 297 次阅读

package main import ( "fmt" "time" ) func main() { timer1 := time.NewTimer(2 * time.Second) <-timer1.C fmt.Println("Timer 1 fired") timer2 := time.NewTimer(time.Second) go func() { <-timer2.C fmt.Println("Timer 2 fired") }() stop2 := timer2.Stop() if stop2 { fmt.Println("Timer 2 stopped") } time.Sleep(2 * time.Second) }$ go run timers.go Timer 1 fired Timer 2 stopped



Timers GO实例 GO

需要 登录 后方可回复, 如果你还没有账号请 注册新账号