咨询一个问题,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()
}
不好意思,是我没看仔细。
After the last value has been received from a closed channel c, any receive from c will succeed without blocking, returning the zero value for the channel element
又看了一遍文档,谢谢,非常感谢您的回答。
#4
更多评论
谢谢解答,但是我还是有点问题。
我看文档里面写的是,读取关闭的channel时候,读取的返回值是相应对象的零值,对象的空值也可以调用他实现的接口么?这个所谓的零值,应该是一未初始化的对象吧?否者是零值的话,应该没办法调用方法了吧?
刚从C++转过来,有点蒙。
谢谢,非常感谢。
#2