🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
> # 片段二 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) } } ~~~