File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change 7373If the coroutine only writes to a channel, the channel is declared as write-only.
7474If the coroutine only has a read operation on a channel, the channe is declared read-only.
7575
76+ ```
77+ onlyread := make(<-chan int) //create only read channel
78+ onlywrite := make(chan<- int) //create only write channel
79+ ```
80+
7681```
7782// Only the generator writes outCh and returns the statement
7883// <-chan int, can prevent other coroutines from using this channel indiscriminately, causing hidden bugs
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ select可以同时监控多个通道的情况,只处理未阻塞的case。当
7373如果协程对某个channel只有写操作,则这个channel声明为只写。
7474如果协程对某个channel只有读操作,则这个channe声明为只读。
7575
76+ ```
77+ chonlyread := make(<-chan int) //创建只读channel
78+ chonlywrite := make(chan<- int) //创建只写channel
79+ ```
80+
7681```
7782// 只有generator进行对outCh进行写操作,返回声明
7883// <-chan int,可以防止其他协程乱用此通道,造成隐藏bug
You can’t perform that action at this time.
0 commit comments