@@ -472,11 +472,17 @@ Channels are good for producer/consumer scenarios, but because each worker
472
472
blocks on receive, it is not such an ideal construct for doing fine-grained
473
473
processing of asynchronously produced streams of values. Additionally, there
474
474
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.
477
476
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
480
486
arguments, the optional ones expresses as named arguments:
481
487
482
488
$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
493
499
if there is an error. This also means there will be no further values.
494
500
495
501
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.
498
504
499
505
my $s = Supply.new;
500
506
@@ -514,19 +520,18 @@ subscribing, call C<close> on it.
514
520
$s.done; # End\n
515
521
516
522
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.
518
524
519
525
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.
522
527
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.
526
531
If the iteration at some point produces an exception, then the C<quit>
527
532
callable will be invoked to pass along the exception.
528
533
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
530
535
ascending value at a regular time interval.
531
536
532
537
Supply.interval(1).tap(&say); # Once a second, starting now
0 commit comments