1.通道的简单例子:
package main
import "fmt"
func main() {
channel:=make(chan string) //创建了一个通道对象
go func() {channel<-"hello world!!!"}() //向通道对象传递数值
go func() {channel<-"test"}()
msg:=<-channel //从通道对象接收数值
fmt.Println(msg) //test
msg1:=<-channel
fmt.Println(msg1) //hello world!!! 后面接收到的数值覆盖前面接收到的数值,后面会学习设置缓冲
}
/*
上面的例子得出以下几个结论:
1.当向没有缓冲的通道发送多个值时,后面先接收到的时候最后发送的值,然后接收到的是前面发送的值
2.如果接收次数,超过发送的数量,编译无法通过
3.可以设置缓冲区 channel:=make(chan string,2) 可以设置成1-n的任意数值,当然不要太大
*/
后面还有工作池的内容,后面再仔细学习