@@ -14,7 +14,7 @@ RE-DRAFT: Synopsis 17: Concurrency
14
14
Created: 3 Nov 2013
15
15
16
16
Last Modified: 19 Nov 2013
17
- Version: 9
17
+ Version: 10
18
18
19
19
This synopsis is based around the concurrency primitives and tools currently
20
20
being implemented in Rakudo on the JVM. It covers both things that are
@@ -483,21 +483,23 @@ of these issues. A C<Supply> pushes or pumps values to one or more receivers
483
483
who have registered their interest.
484
484
485
485
Anything that does the C<Supply> role can be tapped (that is, subscribed to) by calling
486
- the C<tap> method on it. This takes between one and three callables as
487
- arguments:
486
+ the C<tap> method on it. This takes up to three callables as
487
+ arguments, the optional ones expresses as named arguments :
488
488
489
- $supply.tap(
490
- -> $value { say "Got a $value" },
491
- { say "Reached the end" },
492
- -> $ex { say "Got exception: $ex" });
489
+ $supply.tap: -> $value { say "Got a $value" },
490
+ done => { say "Reached the end" },
491
+ catch => {
492
+ when X::FooBar { die "Major oopsie" };
493
+ default { warn "Supply shut down early: $_" }
494
+ }
493
495
494
496
The first, known as C<more>, is invoked whenever a value is produced by the
495
497
thing that has been tapped. The second, known as C<done>, is invoked
496
498
when all values have been produced and no more will be. The final one, known
497
- as C<fail >, is invoked if there is an error. This also means there will be no
499
+ as C<catch >, is invoked if there is an error. This also means there will be no
498
500
further values. Expressing the possible invocations as a grammar:
499
501
500
- more* [ done | fail ]? # invocations
502
+ more* [ done | catch ]? # invocations
501
503
502
504
The simplest Supply is a C<Supply> class, which is punned from the role.
503
505
On the "pumping" end, this has corresponding methods C<more>, C<done>, and
@@ -531,7 +533,7 @@ the tap.
531
533
C<Supply.for> takes a (potentially lazy) list of values, and returns a
532
534
C<Supply> that, when tapped, will iterate over the values and invoke the
533
535
C<more> callable for each of them, and any C<done> callable at the end.
534
- If the iteration at some point produces an exception, then the C<fail >
536
+ If the iteration at some point produces an exception, then the C<catch >
535
537
callable will be invoked.
536
538
537
539
C<Supply.interval> produces a C<Supply> that, when tapped, will produce an
@@ -673,7 +675,7 @@ tapped for its value.)
673
675
Thus there is never any race or other thread-safely problems with
674
676
mutating the C<@as> and C<@bs>. The default behaviour, if a callable is
675
677
specified along with the supply, is to use it for C<more> and provide
676
- a default C<done> and C<fail >. The default C<done> triggers C<done>
678
+ a default C<done> and C<catch >. The default C<done> triggers C<done>
677
679
on the result supply, which is the correct semantics for C<zip>. On
678
680
the other hand, C<merge> wants different semantics, and so must
679
681
provide a C<done>. This can be implemented as follows:
@@ -706,12 +708,9 @@ or conjecturally:
706
708
}
707
709
}
708
710
709
- A C<fail > can be provided in a similar way, although the default - convey the
711
+ A C<catch > can be provided in a similar way, although the default - convey the
710
712
failure to the result supply - is normally what is wanted. The exception
711
- is writing combinators related to error handling. [It's probably a bad idea
712
- to use the word 'fail' here, since it's also an operator.]
713
-
714
- [TODO: specify C<catch> and various other error-handling related timeouts.]
713
+ is writing combinators related to error handling.
715
714
716
715
=head1 The Event Loop
717
716
0 commit comments