Multiplexing with Select
select lets a Goroutine wait on multiple communication operations. It's like a switch statement but for channels.
go select { case msg1 := <-ch1: fmt.Println("Received", msg1) case ch2 <- "hi": fmt.Println("Sent hi") case <-time.After(time.Second): fmt.Println("Timeout") }
This is essential for implementing timeouts and cancellation logic in microservices.