我无法理解这个程序for select,所以我需要帮助来解释这个程序的顺序,
done := make(chan interface{})
go func() {
time.Sleep(5 * time.Second)
close(done)
}()
workcount := 0
loop:
for {
select {
case <-done:
break loop
default:
}
workcount++
fmt.Println(workcount)
time.Sleep(1 * time.Second)
}
fmt.Printf("Achieved %v cycles of work before signalled to stop \n", workcount)
慕尼黑5688855
相关分类