Skip to content

Commit a10573f

Browse files
authored
Clarification on &done and &emit (#4721)
emit and done use control exceptions so you don't have to lexically place them inside a react or supply block. Also mention the LAST phaser in whenver blocks is like the done named argument to method tap. Also, calling &done will return from the supply or react block.
1 parent a53b6fe commit a10573f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

doc/Type/independent-routines.rakudoc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,10 @@ my $supply = supply {
13241324
$supply.tap( -> $v { say "First : $v" });
13251325
=end code
13261326

1327+
C<emit> is implemented as a L<control exception|/language/phasers#CONTROL> and
1328+
can therefore be used by something called from the C<supply> block that it
1329+
refers to.
1330+
13271331
See also L<the page for C<emit> methods|/routine/emit>.
13281332

13291333
=head2 sub undefine
@@ -1459,24 +1463,30 @@ of any subsequent calls to C<exit> in the same, or any other thread.
14591463
sub done(--> Nil)
14601464

14611465
If used outside any supply or react block, throws an exception C<done without
1462-
supply or react>. Within a L<C<Supply>|/type/Supply> block, it will indicate the
1463-
supply will no longer emit anything. See also L<documentation on method
1464-
C<done>|/routine/done>.
1466+
supply or react>. Within a L<C<Supply>|/type/Supply> block, it will signal that
1467+
the supply will not emit further values, and leaves the supply block. See also
1468+
L<documentation on method C<done>|/routine/done>.
1469+
1470+
C<done> is implemented as a L<control exception|/language/phasers#CONTROL> and
1471+
can therefore be used by something called from the C<supply> or C<react> block
1472+
that it refers to.
14651473

14661474
=for code
14671475
my $supply = supply {
14681476
for 1 .. 3 {
14691477
emit($_);
14701478
}
14711479
done;
1480+
say "never reached";
14721481
}
14731482
$supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
14741483
# OUTPUT: «Second : 1␤Second : 2␤Second : 3␤No More␤»
14751484

1476-
The block passed to the C<done> named argument will be run when C<done> is
1477-
called within the C<supply> block.
1485+
The block passed to the C<done> named argument when tapping the supply will be
1486+
run when C<done> is called within the C<supply> block. Similarly, C<whenever>
1487+
blocks that were used to tap the supply will have any C<LAST> phasers called.
14781488

1479-
As of the 2021.06 release of the Rakudo compiler, it is also possibly to
1489+
As of the 2021.06 release of the Rakudo compiler, it is also possible to
14801490
supply a value with C<done>:
14811491

14821492
sub done($value --> Nil)

0 commit comments

Comments
 (0)