Skip to content

Commit 241245c

Browse files
committed
Exit found a better place 🚚
Which closes #1747.
1 parent d924476 commit 241245c

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

doc/Language/routines.pod6

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ See L<Sub> on how to define routines and work with them.
1010
1111
Routines that change the flow of the program, maybe returning a value.
1212
13-
=head2 X<emit>
13+
=head2 sub exit
1414
15-
Defined as
15+
Defined as:
1616
17-
sub emit(\value --> Nil)
17+
sub exit(Int() $status = 0)
1818
19-
If used outside any supply or react block, throws an exception C<emit without
20-
supply or react>. Within a L<Supply> block, it will add a message to the stream.
19+
Exits the current process with return code C<$status> or zero if no value has
20+
been specified. The exit value (C<$status>), when different from zero, has to be
21+
opportunely evaluated from the process that catches it (e.g., a shell).
2122
22-
=begin code
23-
my $supply = supply {
24-
for 1 .. 10 {
25-
emit($_);
26-
}
27-
}
28-
$supply.tap( -> $v { say "First : $v" });
29-
=end code
23+
C<exit> does prevent the L<LEAVE|/language/phasers#LEAVE> phaser to be executed.
3024
31-
See also L<the page for C<emit> methods|/routine/emit>.
25+
C<exit> should be used as last resort only to signal the parent process about an
26+
exit code different from zero, and should not be used to terminate exceptionally
27+
a method or a sub: use L<exceptions|/language/exceptions> instead.
28+
29+
It is worth noting that the only way to return an exit code different from zero
30+
from a L<Main|/routine/MAIN> function is by means of using C<exit>.
3231
3332
=head2 X<done>
3433
@@ -53,6 +52,27 @@ $supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
5352
The block passed to the C<done> named argument will be run when C<done> is
5453
called within the C<supply> block.
5554
55+
=head2 X<emit>
56+
57+
Defined as
58+
59+
sub emit(\value --> Nil)
60+
61+
If used outside any supply or react block, throws an exception C<emit without
62+
supply or react>. Within a L<Supply> block, it will add a message to the stream.
63+
64+
=begin code
65+
my $supply = supply {
66+
for 1 .. 10 {
67+
emit($_);
68+
}
69+
}
70+
$supply.tap( -> $v { say "First : $v" });
71+
=end code
72+
73+
See also L<the page for C<emit> methods|/routine/emit>.
74+
75+
5676
=end pod
5777

5878
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

doc/Type/Any.pod6

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,26 +304,6 @@ is considered to be a key again).
304304
305305
say (a => 1, 'b', 'c').pairup.perl; # OUTPUT: «(:a(1), :b("c")).Seq␤»
306306
307-
=head2 sub exit
308-
309-
Defined as:
310-
311-
sub exit(Int() $status = 0)
312-
313-
Exits the current process with return code C<$status> or zero if no value has been specified.
314-
The exit value (C<$status>), when different from zero, has to be opportunely evaluated from the
315-
process that catches it (e.g., a shell).
316-
317-
C<exit> does prevent the L<LEAVE|/language/phasers#LEAVE> phaser to be executed.
318-
319-
C<exit> should be used as last resort only to signal the parent process about an exit code different from zero,
320-
and should not be used to terminate exceptionally a method or a sub: use L<exceptions|/language/exceptions> instead.
321-
322-
It is worth noting that the only way to return an exit code different from zero from a L<Main|/routine/MAIN> function
323-
is by means of using C<exit>.
324-
325-
=comment TODO maybe find a better place to document &exit
326-
327307
=head2 sub item
328308
329309
X<|$ (item contextualizer)>

0 commit comments

Comments
 (0)