Golang中 channel 以及 groutine 理解
1、Curious Channels
A closed channel never blocks
A nil channel always blocks
A send to a nil channel blocks forever
A receive from a nil channel blocks forever
A send to a closed channel panics
A receive from a closed channel returns the zero value immediately
2.Never start a goroutine without knowing how it will stop
Every time you write the statement go in a program, you should consider the question of how, and under what conditions, the goroutine you are about to start, will end.
select会按照随机的顺序检测各case语句中channel是否ready,如果某个case中的channel已经ready则执行相应的case语句然后退出select流程,如果所有的channel都未ready且没有default的话,则会阻塞等待各个channel
引用:
https://dave.cheney.net/2016/...
【Golang中 channel 以及 groutine 理解】https://dave.cheney.net/2013/...
https://dave.cheney.net/2014/...
The Behavior Of Channels:
https://www.ardanlabs.com/blo...
推荐阅读
- 热闹中的孤独
- Shell-Bash变量与运算符
- JS中的各种宽高度定义及其应用
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 深入理解Go之generate
- 异地恋中,逐渐适应一个人到底意味着什么()
- 我眼中的佛系经纪人
- 《魔法科高中的劣等生》第26卷(Invasion篇)发售
- “成长”读书社群招募
- 2020-04-07vue中Axios的封装和API接口的管理