Skip to content

Commit d0fb631

Browse files
committed
s/fail/catch/ on receiving end, tap has named args
1 parent c5b7d73 commit d0fb631

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

S17-concurrency.pod

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RE-DRAFT: Synopsis 17: Concurrency
1414
Created: 3 Nov 2013
1515

1616
Last Modified: 19 Nov 2013
17-
Version: 9
17+
Version: 10
1818

1919
This synopsis is based around the concurrency primitives and tools currently
2020
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
483483
who have registered their interest.
484484

485485
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:
488488

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+
}
493495

494496
The first, known as C<more>, is invoked whenever a value is produced by the
495497
thing that has been tapped. The second, known as C<done>, is invoked
496498
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
498500
further values. Expressing the possible invocations as a grammar:
499501

500-
more* [ done | fail ]? # invocations
502+
more* [ done | catch ]? # invocations
501503

502504
The simplest Supply is a C<Supply> class, which is punned from the role.
503505
On the "pumping" end, this has corresponding methods C<more>, C<done>, and
@@ -531,7 +533,7 @@ the tap.
531533
C<Supply.for> takes a (potentially lazy) list of values, and returns a
532534
C<Supply> that, when tapped, will iterate over the values and invoke the
533535
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>
535537
callable will be invoked.
536538

537539
C<Supply.interval> produces a C<Supply> that, when tapped, will produce an
@@ -673,7 +675,7 @@ tapped for its value.)
673675
Thus there is never any race or other thread-safely problems with
674676
mutating the C<@as> and C<@bs>. The default behaviour, if a callable is
675677
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>
677679
on the result supply, which is the correct semantics for C<zip>. On
678680
the other hand, C<merge> wants different semantics, and so must
679681
provide a C<done>. This can be implemented as follows:
@@ -706,12 +708,9 @@ or conjecturally:
706708
}
707709
}
708710

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
710712
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.
715714

716715
=head1 The Event Loop
717716

0 commit comments

Comments
 (0)