@@ -10,25 +10,24 @@ See L<Sub> on how to define routines and work with them.
10
10
11
11
Routines that change the flow of the program, maybe returning a value.
12
12
13
- = head2 X < emit >
13
+ = head2 sub exit
14
14
15
- Defined as
15
+ Defined as:
16
16
17
- sub emit(\value --> Nil )
17
+ sub exit(Int() $status = 0 )
18
18
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).
21
22
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.
30
24
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 > .
32
31
33
32
= head2 X < done >
34
33
@@ -53,6 +52,27 @@ $supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
53
52
The block passed to the C < done > named argument will be run when C < done > is
54
53
called within the C < supply > block.
55
54
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
+
56
76
= end pod
57
77
58
78
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
0 commit comments