The select Statement
Multiplexing channels with select
What is select?
The select statement lets a goroutine wait on multiple channel operations simultaneously. It picks the first case that is ready to proceed, similar to a switch but for channels.
Basic Syntax
Each case in a select is a channel send or receive:
select {
case msg := <-ch1:
fmt.Println("ch1:", msg)
case msg := <-ch2:
fmt.Println("ch2:", msg)
}All lessons in this course
- The select Statement
- Timeouts and Tickers
- Fan-in and Fan-out Patterns
- Worker Pool Pattern