liveBook · Manning

Closed channel

As explained in Learn Go with Pocket-Sized Projects

A closed channel is a Go channel on which no further sends are permitted and receives can continue until buffered values are exhausted.

A closed channel permits no further sends, but receives continue: buffered values arrive first, followed by the message type’s zero value. Closing is final, so the channel cannot be reopened. section 9.5.2

Broadcasting a quit signal

A concurrent maze solver closes its quit channel when one explorer finds the treasure: close(s.quit). Every worker can then receive from the closed channel and stop without requiring one quit message per goroutine. section 9.5.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines receive behavior, irreversibility, and multi-goroutine notification, then applies closure to stop exploration.
Examples
Uses a quit channel to stop maze explorers after treasure discovery.
What it assumes
Assumes channel communication and goroutines, then demonstrates closure-based shutdown.
What you can do after
Apply it via Go channel operations to notify multiple goroutines without sending one message per worker.
How it connects
Connects channels with goroutines, select, channel receives, zero values, and channel sends.

Also explained in

Compare how 2 books explain closed channel →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.