如何优雅地关闭Go channel

天唯 ·
咨询一个问题,go语言实战上面的例子,先关闭channel,然后range,这可行么?谢谢 ```go { // Close the channel before we drain the channel of its // resources. If we don't do this, we will have a deadlock. close(p.resources) // Close the resources for r := range p.resources { r.Close() } } ```
#2
更多评论
咨询一个问题,go语言实战上面的例子,先关闭channel,然后range,这可行么?谢谢 // Close the channel before we drain the channel of its // resources. If we don't do this, we will have a deadlock. close(p.resources) // Close the resources for r := range p.resources { r.Close() }
#1
polaris
社区,需要你我一同完善!
关闭的 chan 不能再往里面写了,但可以读。
#3