Channels - Middle¶
Fan-out distributes work; fan-in merges results. Lifecycle coordination matters as much as data flow.
flowchart TD
Input --> W1[Worker 1]
Input --> W2[Worker 2]
W1 --> Results
W2 --> Results
Group[Wait for both] --> Close[Close results]
Use a task group or wait group to close results only after all senders exit. Select between send/receive, cancellation, and deadlines. Size the buffer from measured burst tolerance; it cannot fix a sustained rate mismatch.
Continue to senior.md.
Test yourself¶
- Why must fan-in wait before closing output?
- How does cancellation unblock a sender?
- What can channel occupancy tell you?