Close function
In Go, close is a built-in function that marks a channel closed, preventing further sends and allowing receivers to detect completion.
Learn Go with Pocket-Sized Projects
The close function is a Go built-in that marks a channel as closed so that no more values can be sent on it and receivers can detect completion.
- How it is used
- Uses channel closure to signal completed goroutines, end channel listening, and notify multiple maze-solving workers to quit.
- How deep it goes
- Explains reads after closure, zero values, two-value receives, and shutdown patterns; does not examine runtime internals.
- Examples
- Shows a buffered completion channel and a concurrent maze solver whose workers stop through a quit channel.
- What you can do after
- Practice/perform channel closure to notify waiting goroutines and distinguish completion from a sent zero value.
Read how Learn Go with Pocket-Sized Projects explains close function →
Learn Concurrent Programming with Go
close is a Go built-in function that marks a channel as closed so that no further values can be sent to it.
- How it is used
- Signals that a channel has no more values and lets receivers terminate cleanly.
- How deep it goes
- Explains closure, post-closure reads, the open flag, range loops, and pipeline flushing, but not channel implementation internals.
- Examples
- Uses integer messages, comma-ok receives, range loops, and a longest-words pipeline that flushes results on closure.
- What you can do after
- Apply it by closing channels after final sends and stopping receivers with the open flag or a range loop.
Read how Learn Concurrent Programming with Go explains close function →
Go in Practice, Second Edition
The Go close function marks a channel as unable to accept further sent values and enables receivers to observe that it is closed.
- How it is used
- Coordinates graceful shutdown between goroutines communicating through channels.
- How deep it goes
- Explains send-after-close panics, zero-value receives, comma-ok detection, and a done-channel shutdown pattern.
- Examples
- Uses timeout-driven programs, an improper close panic, comma-ok reception, and a done-channel implementation.
- What you can do after
- Apply it via coordinated sender-side closure and diagnose panics caused by sends racing with closure.
Read how Go in Practice, Second Edition explains close function →
Related concepts
- closed channelproduces · A closed channel is a Go channel that accepts no further sends while allowing receives to complete, including delivery of buffered values.
- deferused by · Defer is a language feature that schedules an operation to execute when the surrounding function or scope exits, including during exceptional unwinding.
- channelused by · A channel is a medium, mechanism, or pathway through which information or messages are conveyed between participants or endpoints.
- channelconfigures · A channel is a typed Go communication and synchronization mechanism through which goroutines send and receive values.
- range clauseaddresses · A range clause iterates over elements of an array, slice, map, or channel and assigns the iteration results to loop variables.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


