ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` func main() { //无缓冲channel ch := make(chan string) go func() { for i:=0;i<2;i++ { fmt.Println("i=", i) time.Sleep(500 * time.Millisecond) } //通知主go打印完毕 ch <- "zi go 打印完毕" }() str := <- ch fmt.Println("str=", str) } 打印: i= 0 i= 1 str= zi go 打印完毕 ``` ``` func main() { // 无缓冲channel ch := make(chan int) go func() { for i:=0;i<5;i++ { fmt.Println("子go程i=", i) ch <- i } }() for i:=0; i<5; i++ { time.Sleep(time.Second) num := <- ch fmt.Println("主go程读:", num) } } ```