💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
CSP并发机制 === ![](https://box.kancloud.cn/8c84140889a2b8cdf2501f9814277857_1130x493.png) golang有两种channel 一种是有缓冲一个是没有缓冲 if 没有缓冲 但channel中有数据 写就会被阻塞,但消费了 还能在写入 ~~~ func TestService(t *testing.T) { dataCh := make(chan int) go production(dataCh) go consume(dataCh) time.Sleep(time.Second * 3) } // 生产者 func production(ch chan int) { for i:=0;i<1000;i++{ ch<-i } } // 消费者 func consume(ch chan int) { for { select { case data := <-ch: fmt.Println(data) } } } ~~~