🐹 Go (Golang)
Intermediate
What is the select statement in Go?
Answer
The select statement lets a goroutine wait on multiple channel operations simultaneously, executing whichever case is ready first. If multiple cases are ready, one is chosen at random — providing fair scheduling. If no case is ready and there is a default clause, the select executes the default immediately (non-blocking select). Without a default, select blocks until at least one case can proceed. Common uses: implementing timeouts (case <-time.After(5*time.Second)), combining a data channel with a done/cancel channel, and fan-in patterns.