Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: 更新口诀
  • Loading branch information
tangx committed Apr 16, 2021
commit ff2aa00f839d7075b7eb36fc963a3e0b02714214
6 changes: 3 additions & 3 deletions 5、channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

* 给一个已经关闭的 channel 发送数据,引起 panic

* 从一个已经关闭的 channel 接收数据,如果缓冲区中为空,则返回**一个零值 和 false** `val,ok:= <-ch1`
* 从一个已经关闭的 channel 接收数据,如果缓冲区中为空,则返回 **一个零值 和 false** (ex: `val,ok:= <-ch1`)

* 无缓冲的channel是同步的,而有缓冲的channel是非同步的

以上5个特性是死东西,也可以通过口诀来记忆:“空读写阻塞,写关闭异常,读关闭空零”。
以上5个特性是死东西,也可以通过口诀来记忆:“读写**空**阻塞,写**关闭**异常,读**关闭空**零假”。

![](images/169-channel异常情况总结.png)

Expand Down Expand Up @@ -58,7 +58,7 @@ func main() {



15字口诀:“空读写阻塞,写关闭异常,读关闭空零”,往已经关闭的channel写入数据会panic的。因为main在开辟完两个goroutine之后,立刻关闭了ch, 结果:
15字口诀:“读写**空**阻塞,写**关闭**异常,读**关闭空**零假”,往已经关闭的channel写入数据会panic的。因为main在开辟完两个goroutine之后,立刻关闭了ch, 结果:

```
panic: send on closed channel
Expand Down