The spawn expression starts one async function invocation, and any expression that follows the spawn is executed immediately while the started async function task continues independently until it completes.
# Continues until completed without blocking
spawn{AsyncFunction1()} # Started at same time as expression0
expression0 # Started at same time as AsyncFunction1()The following code shows the syntax for the spawn expression.
expression0
spawn{ expression1 }
expression2The diagram below shows the execution flow of the expressions.
While similar to branch, the spawn body is limited to a single async function call. It is also allowed outside of an async context, so it can be called within both non-async and async functions.
A spawn expression should be treated like an emergency escape hatch, while branch should be used in place of spawn whenever possible.
Spawn Expression Use
Where you can use a | Any context. |
Invocation time of the | Immediate. |
Requirements for | The body of the |
What the | The body of a |
When the | The |
When the next expression after | Any next expression that follows the |
Result of the | A |