第一章概述了go的简单用法
值得看的就是CSP(Communicating Sequential Process 通信顺序进程)模型
package main
import "time"
func main() {
//阻塞主进程
done := make(chan bool)
//数据传输
data := make(chan int)
go consumer(data, done)
go producer(data)
//阻塞主进程
<-done
}
//消费者
func consumer(data chan int, done chan bool) {
for x := range data {
time.Sleep(time.Second * 3)
println("recv:", x)
}
done <- true
}
//生产者
func producer(data chan int) {
for i := 0; i < 4; i++ {
data <- i
}
close(data)
}
标签:chan,第一章,概述,go,done,data
From: https://www.cnblogs.com/badake/p/17023452.html