File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -178,9 +178,30 @@ If the code inside the block has not finished, the call to C<.result> will
178
178
wait until it is done.
179
179
180
180
A C < start > may also be used on a bare statement (without curly braces).
181
- This is mainly just useful when calling a subroutine / method on an object
181
+ This is mainly useful when calling a subroutine / method on an object
182
182
is the only thing to do asynchronously.
183
183
184
+ sub get42 { 42 }
185
+ my $promise = start get42;
186
+ say $promise.result; # OUTPUT: «42»
187
+
188
+ Note that code executed this way does not have access to the special
189
+ variables L « C < $! > |/syntax/$!» and L « C < $/ > |/syntax/$/» of its outer
190
+ block, but receives new ones, so every asynchronous task has its
191
+ per-task state.
192
+
193
+ Thus, C < try > expressions and regex matches executed in the
194
+ asynchronous task have their per-task state.
195
+
196
+ 'a' ~~ /a/; # $/ is set to 「a」
197
+ try die; # $! is defined now with an anonymous AdHoc exception
198
+ # as a code block
199
+ await start { say $! }; # OUTPUT: «Nil»
200
+ await start { say $/ }; # OUTPUT: «Nil»
201
+ # as a single statement
202
+ await start $!.say; # OUTPUT: «Nil»
203
+ await start $/.say; # OUTPUT: «Nil»
204
+
184
205
= head1 X < if|control flow,if >
185
206
186
207
To conditionally run a block of code, use an C < if > followed by a condition.
You can’t perform that action at this time.
0 commit comments