If we need a channel dedicated to sending data and a channel dedicated to receiving data, we can write:
(We assume the data to be sent and received is 9):
package main
import (
"fmt"
"time"
)
//只写信道定义
type Writter = chan<- int
//只读信道定义
type Reader = <-chan int
func main() {
//声明一个信道
var ch = make(chan int)
go func() {
var writter Writter = ch
fmt.Println("写入数据:9")
writter <- 9
}()
go func() {
var reader Reader = ch
data := <-reader
fmt.Printf("读出数据:%d", data)
}()
time.Sleep(time.Second)
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。