A done channel coordinates clean shutdown between goroutines. The receiving goroutine signals completion, while the sending goroutine stops work, closes the message channel, and returns. section 5.3.2
Use the pattern to avoid common channel-lifecycle failures:
- Let the sender close the message channel; closing it from a receiver while a send is active causes a panic. section 5.3.2
- Do not treat a closed channel's zero value as an ordinary message; receive its status when distinguishing closure matters. section 5.3.2
- Give the sender a dedicated done channel and select on it so cancellation can trigger cleanup before return. section 5.3.2
Timed producer shutdown
A main goroutine reads messages until a timeout, sends a completion signal on done, and returns. The producer selects on done, logs completion, closes its output channel, and exits; otherwise it sends another message and waits briefly.
