How to Use select Statement in Go (Channel Multiplexing)

Use the select statement with case clauses to block until one of multiple channels is ready for communication.

Use a select statement with multiple case clauses to wait on several channels simultaneously, executing the first one that becomes ready.

select {
case msg := <-ch1:
    fmt.Println("Received from ch1:", msg)
case msg := <-ch2:
    fmt.Println("Received from ch2:", msg)
default:
    fmt.Println("No messages ready")
}

If you need to wait indefinitely until a channel is ready, omit the default case.