← All notes

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

Sources

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

Permanent ID: iil:note:pvahvx54

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.},
}

Markdown

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.

All artifact files (JSON index)

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.