标签:演示 通道 sele div received ack 选择 time 运行
代码演示
package main import "fmt" import "time" func main() { c1 := make(chan string) c2 := make(chan string) go func() { time.Sleep(time.Second * 1) c1 <- "one" }() go func() { time.Sleep(time.Second * 2) c2 <- "two" }() for i := 0; i < 2; i++ { select { case msg1 := <-c1: fmt.Println("received", msg1) case msg2 := <-c2: fmt.Println("received", msg2) } } }
代码运行结果
received one received two
代码解读
标签:演示 通道 sele div received ack 选择 time 运行
原文地址:https://www.cnblogs.com/Joestar/p/8799255.html