select { case v := <-ch1: ... case ch2 <- x: ... default: ... } chờ multiple channel operations, chạy case sẵn sàng đầu tiên.
- Nếu nhiều case sẵn sàng → chọn random.
defaultchạy nếu không case nào sẵn sàng (non-blocking). - Dùng cho timeout:
case <-time.After(5*time.Second).
select { case v := <-ch1: ... case ch2 <- x: ... default: ... } waits on multiple channel operations and runs the first one ready.
- If multiple cases are ready, one is chosen at random.
defaultruns immediately if no case is ready (non-blocking). - Useful for timeouts:
case <-time.After(5*time.Second).