企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> # 片段二 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) } } ~~~