0PricingLogin
Go Academy · Lesson

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

  1. The select Statement
  2. Timeouts and Tickers
  3. Fan-in and Fan-out Patterns
  4. Worker Pool Pattern
← Back to Go Academy