Skip to content

Commit 1ce6c0b

Browse files
committed
Additional clarification on consumeEach vs for loop iteration
1 parent 58c61c7 commit 1ce6c0b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

coroutines-guide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,11 @@ Processor #3 received 10
15711571
Note, that cancelling a producer coroutine closes its channel, thus eventually terminating iteration
15721572
over the channel that processor coroutines are doing.
15731573

1574+
Also, pay attention to how we explicitly iterate over channel with `for` loop to perform fan-out in `launchProcessor` code.
1575+
Unlike `consumeEach`, this `for` loop pattern is perfectly safe to use from multiple coroutines. If one of the processor
1576+
coroutines fails, then others would still be processing the channel, while a processor that is written via `consumeEach`
1577+
always consumes (cancels) the underlying channel on its normal or abnormal termination.
1578+
15741579
### Fan-in
15751580

15761581
Multiple coroutines may send to the same channel.

0 commit comments

Comments
 (0)