Skip to content

Commit 4d7ca45

Browse files
committed
Elaborate on "on demand" and "live" Supply
1 parent c71f130 commit 4d7ca45

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

S17-concurrency.pod

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,17 @@ Channels are good for producer/consumer scenarios, but because each worker
472472
blocks on receive, it is not such an ideal construct for doing fine-grained
473473
processing of asynchronously produced streams of values. Additionally, there
474474
can only be one receiver for each value. Supplies exist to address both
475-
of these issues. A C<Supply> pushes or pumps values to one or more receivers
476-
who have registered their interest.
475+
of these issues.
477476

478-
Anything that does the C<Supply> role can be tapped (that is, subscribed to) by calling
479-
the C<tap> method on it. This takes up to three callables as
477+
A C<Supply> pushes or pumps values to one or more receivers who have registered
478+
their interest. There are two types of Supplies: C<live> and C<on demand>.
479+
When tapping into a C<live> supply, the tap will only see values that have
480+
been pumped B<after> the tap has been created. A tap on an C<on demand>
481+
supply will always see B<all> values that have been / will be pumped into the
482+
supply, regardless of when the tap is created.
483+
484+
Anything that does the C<Supply> role can be tapped (that is, subscribed to)
485+
by calling the C<tap> method on it. This takes up to three callables as
480486
arguments, the optional ones expresses as named arguments:
481487

482488
$supply.tap: -> $value { say "Got a $value" },
@@ -493,8 +499,8 @@ will be. The optional named parameter C<quit> specifies the code to be invoked
493499
if there is an error. This also means there will be no further values.
494500

495501
The simplest Supply is a C<Supply> class, which is punned from the role.
496-
On the "pumping" end, this has corresponding methods C<more>, C<done>, and
497-
C<quit>, which notify all current taps.
502+
It creates a C<live> supply. On the "pumping" end, this has corresponding
503+
methods C<more>, C<done>, and C<quit>, which notify all current taps.
498504

499505
my $s = Supply.new;
500506

@@ -514,19 +520,18 @@ subscribing, call C<close> on it.
514520
$s.done; # End\n
515521

516522
This doesn't introduce any asynchrony directly. However, it is possible for
517-
values to be pumped by a C<Supply> from an asynchronous worker.
523+
values to be pumped into a C<Supply> from an asynchronous worker.
518524

519525
The C<Supply> class has various methods that produce more interesting kinds of
520-
C<Supply>. These default to working asynchronously. Furthermore, they start
521-
producing values upon the point of the tap.
526+
C<Supply>. These default to working asynchronously.
522527

523-
C<Supply.for> takes a (potentially lazy) list of values, and returns a
524-
C<Supply> that, when tapped, will iterate over the values and invoke the
525-
C<more> callable for each of them, and any C<done> callable at the end.
528+
C<Supply.for> takes a (potentially lazy) list of values, and returns an
529+
on demand C<Supply> that, when tapped, will iterate over the values and invoke
530+
the C<more> callable for each of them, and any C<done> callable at the end.
526531
If the iteration at some point produces an exception, then the C<quit>
527532
callable will be invoked to pass along the exception.
528533

529-
C<Supply.interval> produces a C<Supply> that, when tapped, will produce an
534+
C<Supply.interval> produces a live C<Supply> that, when tapped, will produce an
530535
ascending value at a regular time interval.
531536

532537
Supply.interval(1).tap(&say); # Once a second, starting now

0 commit comments

Comments
 (0)