我想知道在退出程序之前等待程序完成的正确方法是什么.阅读其他一些答案似乎bool chan会做到这一点,就像Playground链接一样
func do_stuff(done chan bool) {
fmt.Println("Doing stuff")
done <- true
}
func main() {
fmt.Println("Main")
done := make(chan bool)
go do_stuff(done)
<-done
//<-done
}
Run Code Online (Sandbox Code Playgroud)
我这里有两个问题:
为什么< - 完成工作?
如果我取消注释最后一行会发生什么?我有一个死锁错误.这是因为频道是空的,没有其他功能向它发送值?