英文:
Explain <-(chan string)(nil)
问题
我在Gobetween的源代码中发现了这个奇怪的构造<-(chan string)(nil)。
- 它只是一种花哨的方式永久阻塞,还是相比于
select{}有某种优势? 如何解析这个语句?
英文:
I found this <-(chan string)(nil) strange construct in the Gobetween sources.
- Is it just a fancy way to block forever or it has some kind of advantage over
select{}? - <s>How to parse this statement?</s>
答案1
得分: 3
该语句将nil转换为类型为chan string的通道,然后从中读取。
从空通道接收将永远阻塞
英文:
The statement casts nil as type chan string, then reads from it.
According to Dave Cheney's Channel Axioms:
A receive from a nil channel blocks forever
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论