Skip to content

Commit

Permalink
emit and done moved to independent routines page, closes #1032, refs #…
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed May 28, 2019
1 parent 03274aa commit d48f966
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
48 changes: 0 additions & 48 deletions doc/Language/routines.pod6
Expand Up @@ -6,54 +6,6 @@
See L<Sub|/type/Sub> on how to define routines and work with them.
=head1 Control routines
Routines that change the flow of the program, maybe returning a value.
=head2 sub exit
Defined as:
sub exit(Int() $status = 0)
Exits the current process with return code C<$status> or zero if no
value has been specified. The exit value (C<$status>), when different
from zero, has to be opportunely evaluated from the process that catches
it (e.g., a shell); it is the only way to return an exit code different
from zero from a L<Main|/routine/MAIN>.
C<exit> prevents the L<LEAVE|/language/phasers#LEAVE> phaser to be
executed, but it will run the code in the
L<C<&*EXIT>|/language/variables#index-entry-%24*EXIT> variable.
C<exit> should be used as last resort only to signal the parent process
about an exit code different from zero, and not to terminate
exceptionally a method or a sub: use L<exceptions|/language/exceptions>
instead.
=head2 X<done>
Defined as
sub done(--> Nil)
If used outside any supply or react block, throws an exception C<done without
supply or react>. Within a L<Supply|/type/Supply> block, it will indicate the supply will no
longer emit anything. See also L<documentation on method C<done>|/routine/done>.
=for code
my $supply = supply {
for 1 .. 3 {
emit($_);
}
done;
}
$supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
# OUTPUT: OUTPUT: «Second : 1␤Second : 2␤Second : 3␤No More␤»
The block passed to the C<done> named argument will be run when C<done> is
called within the C<supply> block.
=head2 X<emit>
Expand Down
49 changes: 49 additions & 0 deletions doc/Type/independent-routines.pod6
Expand Up @@ -1036,6 +1036,55 @@ operator:
say [42, "42"].squish(with => &infix:<eq>); # OUTPUT: «(42)␤»
# The resulting item is Int
=head1 Control routines
Routines that change the flow of the program, maybe returning a value.
=head2 sub exit
Defined as:
sub exit(Int() $status = 0)
Exits the current process with return code C<$status> or zero if no
value has been specified. The exit value (C<$status>), when different
from zero, has to be opportunely evaluated from the process that catches
it (e.g., a shell); it is the only way to return an exit code different
from zero from a L<Main|/routine/MAIN>.
C<exit> prevents the L<LEAVE|/language/phasers#LEAVE> phaser to be
executed, but it will run the code in the
L<C<&*EXIT>|/language/variables#index-entry-%24*EXIT> variable.
C<exit> should be used as last resort only to signal the parent process
about an exit code different from zero, and not to terminate
exceptionally a method or a sub: use L<exceptions|/language/exceptions>
instead.
=head2 sub X<done>
Defined as
sub done(--> Nil)
If used outside any supply or react block, throws an exception C<done without
supply or react>. Within a L<Supply|/type/Supply> block, it will indicate the supply will no
longer emit anything. See also L<documentation on method C<done>|/routine/done>.
=for code
my $supply = supply {
for 1 .. 3 {
emit($_);
}
done;
}
$supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
# OUTPUT: OUTPUT: «Second : 1␤Second : 2␤Second : 3␤No More␤»
The block passed to the C<done> named argument will be run when C<done> is
called within the C<supply> block.
=end pod

Expand Down

0 comments on commit d48f966

Please sign in to comment.