Don't communicate by sharing memory; share memory by communicating。深入 channel 与 select 模式。
package main
import ("fmt")
func main() {
ch := make(chan string)
go func() {
ch <- "hello from goroutine"
}()
fmt.Println(<-ch)
}
select {
case msg := <-ch1:
fmt.Println("ch1: " + msg)
case msg := <-ch2:
fmt.Println("ch2: " + msg)
default:
fmt.Println("no message")
}