Skip to content

Commit 828b3dd

Browse files
author
刘建秋
committed
chan update
1 parent c00ad36 commit 828b3dd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

EN/channel/channel-1.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ The results and meaning of ok:
5353
-`true`: read the channel data, not sure if it is closed, maybe the channel has saved data, but the channel is closed
5454
-`false`: The channel is closed and no data is read.
5555
56-
* 3. Use select to handle multiple channels
56+
* 3. Use select to handle multiple channel
5757
Scenes
58-
When multiple channels need to be processed simultaneously, but only the channel that occurs first is processed
58+
When multiple channel need to be processed simultaneously, but only the channel that occurs first is processed
5959
60-
Select can monitor the situation of multiple channels at the same time, and only handle unblocked cases. When the channel is nil, the corresponding case is always blocked, regardless of reading or writing. Special attention: Under normal circumstances, writing to the nil channel is panic.
60+
Select can monitor the situation of multiple channel at the same time, and only handle unblocked cases. When the channel is nil, the corresponding case is always blocked, regardless of reading or writing. Special attention: Under normal circumstances, writing to the nil channel is panic.
6161
6262
6363
* 4. Use the channel statement to control read and write permissions
@@ -95,11 +95,11 @@ func consumer (inCh <-chan int) {
9595
}
9696
```
9797
98-
* 5. Use buffered channels to enhance concurrency
98+
* 5. Use buffered channel to enhance concurrency
9999
Scenes
100100
asynchronous
101101
102-
There are buffer channels for multiple coroutines to process at the same time, which can improve concurrency to a certain extent.
102+
There are buffer channel for multiple coroutines to process at the same time, which can improve concurrency to a certain extent.
103103
usage
104104
```
105105
// no buffer
@@ -149,7 +149,7 @@ All coroutines that read ch will receive the close (ch) signal
149149
150150
* 9. Use chan struct {} as signal channel
151151
Scenes
152-
Use channels to pass signals instead of data
152+
Use channel to pass signals instead of data
153153
154154
When there is no data to pass, pass an empty struct
155155

EN/channel/channel.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
* Channle essential data structure pipeline queue, data is first-in first-out.
77
* With ** thread safety mechanism **, when multiple go programs are accessed, no shackles are needed, which means that the channel itself is thread safe.
8-
* Channels are typed.
8+
* channel are typed.
9+
* Notes for closed channel:
10+
- 1. Sending another value on a closed channel causes a panic.
11+
- 2. Receiving a closed channel will get the value until the channel is empty.
12+
- 3. Performing a receive operation on a closed channel with no value will result in a zero value of the corresponding type.
13+
- 4. Closing a closed ** channel causes panic.
914

1015
### channel traversal mode
1116

@@ -68,7 +73,7 @@ break
6873
Notes on traversal method:
6974
Summary: Through the above verification, in order to ensure the robustness of the program, when designing the program, it is best to read and write the channel separately in the sub-go process. After writing the data, remember to close the channel, so as to avoid blocking and cause the main program to crash, and at the same time capture the subroutine error information.
7075

71-
* Channels do not need to be closed as often as files. Only when you do not have any data to send, or you want to explicitly end the range loop, etc., do you close the channel;
76+
* channel do not need to be closed as often as files. Only when you do not have any data to send, or you want to explicitly end the range loop, etc., do you close the channel;
7277
* After closing the channel, it is impossible to send data to the channel again (after a panic error is caused, the receiver immediately returns zero);
7378
* After closing the channel, you can continue to receive data from the channel;
7479
* For nil channel, no matter sending or receiving, it will be blocked.

zh_CN/channel/channel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
* channle 本质数据结构管道队列,数据是先进先出。
77
* 具有**线程安全机制**,多个go程访问时,不需要枷锁,也就是说channel本身是线程安全的。
88
* channel是有类型的。
9+
* 已关闭通道注意事项:
10+
- 1.对一个关闭的通道再发送值就会导致panic。
11+
- 2.对一个关闭的通道进行接收会一直获取值直到通道为空。
12+
- 3.对一个关闭的并且没有值的通道执行接收操作会得到对应类型的零值。
13+
- 4.关闭一个**已经关闭**的通道会导致panic。
914

1015
### channel 遍历模式
1116

0 commit comments

Comments
 (0)