Await Future (Section) — skLambda
Addon: skLambda · Category: Section · Since: 1.3.0
Syntax
wait for %future% [(within|for at most|for up to) %-timespan%]Description
Suspends the trigger until one or more futures resolve (or an optional timeout elapses), then continues. The server keeps ticking while the trigger waits: it suspends rather than blocking. `wait for %future% [(within|for at most) %timespan%]:` waits for a single future. `wait for all of %futures% [...]:` waits until every future resolves (when-all). `wait for any of %futures% [...]:` waits until the first one resolves (when-any). The section body runs once the wait resolves; read values with `result of %future%` (the future is resolved by then). An optional `on timeout:` block, nested inside, runs instead if the timeout elapses. Locals set in either branch carry forward to the code after the block.
Examples
set {_f} to future of calling lambda {_slow} with {_p}
# ... other work runs while it computes ...
wait for {_f} for at most 5 seconds:
set {_r} to result of {_f}
send "got %{_r}%" to {_p}
on timeout:
send "timed out" to {_p}