package main

import ( "fmt" "time" )

func main() { done := make(chan bool) go func() { for { fmt.Println('I am a infinite loop') time.Sleep(time.Second) } done <- true }()

select {
case <-time.After(3 * time.Second):
	fmt.Println('Finished after 3 seconds')
case <-done:
	fmt.Println('Finished with done')
}

}

Golang 死循环 3 秒结束代码示例

原文地址: https://www.cveoy.top/t/topic/lrOx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录