In a rush expression, all expressions in the rush block run concurrently, but as soon as one expression completes, the rush expression yields control back and the other expressions continue to run independently. rush is a structured concurrency expression.
The rush expression is used to run a block of two or more async expressions concurrently (simultaneously).
When the fastest subexpression completes, any expression that follows the rush is evaluated, and any remaining subexpressions continue to evaluate.
set WinnerResult = rush:
# All three async functions start at the same time
AsyncFunctionLongTime()
AsyncFunctionShortTime() # This will win and its result is used
AsyncFunctionMediumTime()
# Next expression is called after the fastest async function (AsyncFunctionShortTime()) completes.
# All other subexpression tasks (AsyncFunctionLongTime(), AsyncFunctionMediumTime()) continue.
NextExpression(WinnerResult)
AsyncFunction4()
# If any rush subexpression tasks are still running when AsyncFunction4 completes
The following code shows the syntax for the rush expression.
expression0
rush:
slow-expression
mid-expression
fast-expression
expression1The diagram below shows the execution flow for the expressions.
Rush Expression Use
Where you can use a | |
Invocation time of the | Async |
Requirements for | The body of the |
What the | Is similar to |
When the | The |
When the next expression after | Any next expression that follows the |
Result of the | The result of a |
A rush expression cannot currently be used in the body of an iteration expression like loop or for. If it must be used, then wrap it in an async function and have the iteration expression call that function.