// Chapter 39 example: select waits on two channels at once, and takes // whichever is ready first. // Run with: go run exercises/39/01-select.go package main import ( "fmt" "time" ) func main() { tea := make(chan string) toast := make(chan string) go func() { time.Sleep(300 * time.Millisecond) tea <- "tea is ready" }() go func() { time.Sleep(100 * time.Millisecond) toast <- "toast is ready" }() for range 2 { select { case msg := <-tea: fmt.Println("Tea channel:", msg) case msg := <-toast: fmt.Println("Toast channel:", msg) } } }