gpt4 book ai didi

go - 谁能解释 <-done 将在关闭后运行的执行

转载 作者:数据小太阳 更新时间:2023-10-29 03:46:21 25 4
gpt4 key购买 nike

<分区>

我无法理解这个程序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)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com