You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EN/channel/channel-1.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,11 +53,11 @@ The results and meaning of ok:
53
53
-`true`: read the channel data, not sure if it is closed, maybe the channel has saved data, but the channel is closed
54
54
-`false`: The channel is closed and no data is read.
55
55
56
-
* 3. Use select to handle multiple channels
56
+
* 3. Use select to handle multiple channel
57
57
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
59
59
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.
61
61
62
62
63
63
* 4. Use the channel statement to control read and write permissions
Copy file name to clipboardExpand all lines: EN/channel/channel.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,12 @@
5
5
6
6
* Channle essential data structure pipeline queue, data is first-in first-out.
7
7
* 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.
9
14
10
15
### channel traversal mode
11
16
@@ -68,7 +73,7 @@ break
68
73
Notes on traversal method:
69
74
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.
70
75
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;
72
77
* 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);
73
78
* After closing the channel, you can continue to receive data from the channel;
74
79
* For nil channel, no matter sending or receiving, it will be blocked.
0 commit comments