4
4
5
5
= SUBTITLE Running process (asynchronous interface)
6
6
7
- class Proc::Async { ... }
7
+ = begin code :skip-test
8
+ class Proc::Async {}
9
+ = end code
8
10
9
11
B < Note: > only the MoarVM backend of Rakudo implements C < Proc::Async > at the
10
12
moment.
@@ -30,9 +32,11 @@ standard output and error handles, and optionally write to its standard input.
30
32
31
33
This produces the following output:
32
34
35
+ = begin code :skip-test
33
36
Starting...
34
37
Output: foo bar
35
38
Done.
39
+ = end code
36
40
37
41
An example that opens an external program for writing:
38
42
@@ -47,7 +51,7 @@ An example that opens an external program for writing:
47
51
48
52
= head2 method new
49
53
50
- method new(:$path, *@args, :$w) returns Proc::Async:D
54
+ method new(:$path, *@args, :$w) returns Proc::Async:D {}
51
55
52
56
Creates a new C < Proc::Async > object with external program name or path C < $path >
53
57
and the command line arguments C < @args > .
@@ -58,13 +62,14 @@ C<say>.
58
62
59
63
= head2 method stdout
60
64
61
- method stdout(Proc::Async:D: :$bin) returns Supply:D
65
+ method stdout(Proc::Async:D: :$bin) returns Supply:D {}
62
66
63
67
Returns the L < Supply|/type/Supply > for the external program's standard output
64
68
stream. If C < :bin > is passed, the standard output is passed along in binary as
65
69
L < Blob|/type/Blob > , otherwise it is interpreted as UTF-8, decoded, and passed
66
70
along as L < Str|/type/Str > .
67
71
72
+ my $proc = Proc::Async.new(:r, 'echo', 'Perl 6');
68
73
$proc.stdout.tap( -> $str {
69
74
say "Got output '$str' from the external program";
70
75
});
@@ -82,13 +87,14 @@ you try.
82
87
83
88
= head2 method stderr
84
89
85
- method stderr(Proc::Async:D: :$bin) returns Supply:D
90
+ method stderr(Proc::Async:D: :$bin) returns Supply:D {}
86
91
87
92
Returns the L < Supply|/type/Supply > for the external program's standard error
88
93
stream. If C < :bin > is passed, the standard error is passed along in binary as
89
94
L < Blob|/type/Blob > , otherwise it is interpreted as UTF-8, decoded, and passed
90
95
along as L < Str|/type/Str > .
91
96
97
+ my $proc = Proc::Async.new(:r, 'echo', 'Perl 6');
92
98
$proc.stderr.tap( -> $str {
93
99
say "Got error '$str' from the external program";
94
100
});
@@ -106,15 +112,15 @@ you try.
106
112
107
113
= head2 method w
108
114
109
- method w(Proc::Async:D:)
115
+ method w(Proc::Async:D:) {}
110
116
111
117
Returns a true value if C < :w > was passed to the constructor, that is, if the
112
118
external program is started with its input stream made available to output to
113
119
the program through the C < .print > , C < .say > and C < .write > methods.
114
120
115
121
= head2 method start
116
122
117
- method start(Proc::Async:D:, :$scheduler = $*SCHEDULER, :$cwd = $*CWD) returns Promise:D
123
+ method start(Proc::Async:D: :$scheduler = $*SCHEDULER, :$cwd = $*CWD) returns Promise:D {}
118
124
119
125
Initiates spawning of the external program. Returns a promise that will be
120
126
kept with a L < Proc|/type/Proc > object once the external
@@ -127,38 +133,42 @@ thrown.
127
133
128
134
Note: If you wish to C < await > the Promise and discard its result, using
129
135
136
+ = begin code :skip-test
130
137
try await $p.start;
138
+ = end code
131
139
132
140
B < will throw > if the program exited with non-zero status, as the C < Proc >
133
141
returned as the result of the Promise throws when sunk and in this case it
134
142
will get sunk outside the C < try > . To avoid that, sink it yourself I < inside > the
135
143
C < try > :
136
144
145
+ = begin code :skip-test
137
146
try sink await $p.start;
147
+ = end code
138
148
139
149
= head2 method started
140
150
141
- method started(Proc::Async:D:) returns Bool:D
151
+ method started(Proc::Async:D:) returns Bool:D {}
142
152
143
153
Returns C < False > before C < .start > has been called, and C < True > afterwards.
144
154
145
155
= head2 method path
146
156
147
- method path(Proc::Async:D:)
157
+ method path(Proc::Async:D:) {}
148
158
149
159
Returns the name and/or path of the external program that was passed to the
150
160
C < new > method as first argument.
151
161
152
162
= head2 method args
153
163
154
- method args(Proc::Async:D:) returns Positional:D
164
+ method args(Proc::Async:D:) returns Positional:D {}
155
165
156
166
Returns the command line arguments for the external programs, as passed to the
157
167
C < new > method.
158
168
159
169
= head2 method write
160
170
161
- method write(Proc::Async:D: Blob:D $b, :$scheduler = $*SCHEDULER)
171
+ method write(Proc::Async:D: Blob:D $b, :$scheduler = $*SCHEDULER) {}
162
172
163
173
Write the binary data in C < $b > to the standard input stream of the external
164
174
program.
@@ -175,7 +185,7 @@ L<X::Proc::Async::MustBeStarted> exception is thrown.
175
185
176
186
= head2 method print
177
187
178
- method print(Proc::Async:D: Str(Any) $str, :$scheduler = $*SCHEDULER)
188
+ method print(Proc::Async:D: Str(Any) $str, :$scheduler = $*SCHEDULER) {}
179
189
180
190
Write the text data in C < $str > to the standard input stream of the external
181
191
program, encoding it as UTF-8.
@@ -192,7 +202,7 @@ L<X::Proc::Async::MustBeStarted> exception is thrown.
192
202
193
203
= head2 method say
194
204
195
- method say(Proc::Async:D: $output, :$scheduler = $*SCHEDULER)
205
+ method say(Proc::Async:D: $output, :$scheduler = $*SCHEDULER) {}
196
206
197
207
Calls method C < gist > on the C < $output > , adds a newline, encodes it as UTF-8,
198
208
and sends it to the standard input stream of the external
@@ -210,7 +220,7 @@ L<X::Proc::Async::MustBeStarted> exception is thrown.
210
220
211
221
= head2 method close-stdin
212
222
213
- method close-stdin(Proc::Async:D:)
223
+ method close-stdin(Proc::Async:D:) {}
214
224
215
225
Closes the standard input stream of the external program. Programs that read
216
226
from STDIN often only terminate when their input stream is closed. So if
@@ -226,7 +236,7 @@ L<X::Proc::Async::MustBeStarted> exception is thrown.
226
236
227
237
= head2 method kill
228
238
229
- kill(Proc::Async:D: $signal = "HUP")
239
+ method kill(Proc::Async:D: $signal = "HUP") {}
230
240
231
241
Sends a signal to the running program. The signal can be a signal name
232
242
("KILL" or "SIGKILL"), an integer (9) or an element of the C < Signal > enum
0 commit comments