Skip to content

Commit e585e69

Browse files
author
刘建秋
committed
make chan power
1 parent 828b3dd commit e585e69

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

EN/channel/channel-1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ usage
7373
If the coroutine only writes to a channel, the channel is declared as write-only.
7474
If 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

zh_CN/channel/channel-1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)