Go select: waiting on multiple channel operations
Answer: A select statement chooses among a set of possible send or receive operations. If none can proceed and there is no default case, it blocks until one can.
What the spec requires
It looks similar to a switch statement, but the cases all refer to communication operations.
At most one default case is allowed, and it may appear anywhere in the list of cases.
When several communications can proceed, one of them is chosen by uniform pseudo-random selection.
Otherwise, if there is a default case, that case is chosen. Without a default, select blocks until at least one communication can proceed.
A default case in practice
Effective Go shows a client that keeps a free list and uses a buffered channel to represent that list.
If the channel is empty, a new buffer gets allocated. The example uses a default case in select to do that.
The server loop returns the buffer to the free list.
See also
Claims
- id: C1 claim: select chooses which of a set of possible send or receive operations will proceed. source: S2 evidence: "chooses which of a set of possible"
- id: C2 claim: There can be at most one default case. source: S2 evidence: "There can be at most one default case"
- id: C3 claim: With no default case, select blocks until a communication can proceed. source: S2 evidence: "the \"select\" statement blocks until"
- id: C4 claim: Effective Go uses select with a default case to allocate a buffer when a free list is empty. source: S1 evidence: "If the channel is empty, a new buffer gets allocated"
Sources
- [S1] Effective Go, Channels. Go project. https://go.dev/doc/effective_go#channels . License: CC-BY-4.0. Accessed 2026-11-23.
- [S2] The Go Programming Language Specification, Select statements. Go project. https://go.dev/ref/spec#Select_statements . License: CC-BY-4.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go project, Effective Go, Channels; Go project, The Go Programming Language Specification, Select statements. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go project, Effective Go, Channels; Go project, The Go Programming Language Specification, Select statements. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go select: waiting on multiple channel operations." iinventedlight Library, iil:note:pvahvx54, version of 2026-11-23. https://iinventedlight.com/library/notes/go-select-statement/. License: CC-BY-4.0.
@misc{iil_note_pvahvx54,
author = {{iinventedlight}},
title = {{Go select: waiting on multiple channel operations}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-select-statement/},
note = {Permanent ID iil:note:pvahvx54. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-select-statement.schema.json (schema; CC-BY-4.0)
- go-select-statement.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-select-statement.md.