Skip to content

Commit 1e5230f

Browse files
committed
clarify why more/done distinction in winner works
more only makes sense on on channels, while done only works on promises, and hence will happily autocoerce a channel to its 'done' promise.
1 parent 7e64b6c commit 1e5230f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

S17-concurrency.pod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,19 @@ This is such a common pattern that we make a channel in list context behave that
466466
(Note that this is not a combinator, but a means for transfering data from the reactive
467467
realm to the lazy realm. Some reasonable amount of buffering is assumed between the two.)
468468

469+
We didn't have to use C<*> above; instead we could have said:
470+
471+
gather loop {
472+
winner $c {
473+
more $c { take $_ }
474+
done $c { last }
475+
}
476+
}
477+
478+
This works because C<more> only ever works on channels, while C<done>
479+
only ever works on promises, so it knows to check the promise of
480+
channel C<$c> rather than C<$c> itself.
481+
469482
=head2 Supplies
470483

471484
Channels are good for producer/consumer scenarios, but because each worker

0 commit comments

Comments
 (0)