File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,33 @@ parenthesize a statement if it is the last thing in an expression:
128
128
= for code :skip-test<syntax error>
129
129
3, if 1 { 2 } ; # Syntax error
130
130
131
- ...which brings us to C < if > .
131
+ = head1 X < start|control flow,start >
132
+
133
+ The simplest way to run a block B < asynchronously > is by writing C < start >
134
+ before it:
135
+
136
+ = for code
137
+ start { sleep 1; say "done" }
138
+ say "working";
139
+ # working, done
140
+
141
+ Note that you need a space between the C < start > and the block.
142
+
143
+ The C < start {...} > immediately returns a C < Promise > that can be safely ignored
144
+ if you are not interested in the result of the block. If you B < are > interested
145
+ in the final value of the block, you can call the C < .result > method on the
146
+ returned promise. So:
147
+
148
+ my $promise = start { sleep 10; 42 }
149
+ # ... do other stuff
150
+ say "The result is $promise.result()";
151
+
152
+ If the code inside the block has not finished, the call to C < .result > will
153
+ wait until it is done.
154
+
155
+ A C < start > may also be used on a bare statement (without curly braces).
156
+ This is mainly just useful when calling a subroutine / method on an object
157
+ is the only thing to do asynchronously.
132
158
133
159
= head1 X < if|control flow,if >
134
160
You can’t perform that action at this time.
0 commit comments