多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> # 片段二 channel ~~~ package main import "fmt" func main() { ch1 := make(chan int) ch2 := make(chan string) ch1 <- 1 ch2 <- "2" select { case c1 := <-ch1: fmt.Println(c1) case c2 := <-ch2: panic(c2) } } ~~~ ~~~ package main import ( "fmt" ) func main() { ch1 := make(chan int) ch2 := make(chan string) go func() { ch2 <- "Hello, Go!" }() go func() { ch1 <- 42 }() select { case value := <-ch1: fmt.Printf("Received from ch1: %d\n", value) case message := <-ch2: fmt.Printf("Received from ch2: %s\n", message) } } ~~~