9.2. Async/await coroutine macros
The ASYNC_BOOST module implements an async/await pattern for daslang using
channels and coroutines. It provides async for launching concurrent tasks
and await for waiting on their results, built on top of the job queue
infrastructure.
All functions and symbols are in “async_boost” module, use require to get access to it.
require daslib/async_boost
9.2.1. Function annotations
- async_boost.AwaitMacro
Function annotation that implements coroutine await semantics.
- async_boost.AwaitCoroutineMacro
This macro converts await(<coroutine>) expression into:
for t in THAT
yield t
The idea is that coroutine or generator can continuously yield from another sub-coroutine or generator.
- async_boost.async
This macro converts function into generator. Generator yields bool if its a void function (coroutine), and yields the return type otherwise (async return). async function can wait for another async function using await(<async fn call>). use ‘return false’ to immediately return from the generator.
9.2.2. Awaiting
9.2.2.1. await
- async_boost.await(a: iterator<bool>): bool
This function is used to wait for the result of the async function.
- Arguments:
a : iterator<bool>
- async_boost.await(a: iterator<variant<res:auto(T);wait:bool>>): T
- async_boost.await_next_frame()
This function is used to suspend coroutine until next frame.
9.2.3. Running async tasks
- async_boost.async_run(a: iterator<auto>): auto
This function runs async function until it is finished.
- Arguments:
a : iterator<auto>
- async_boost.async_run_all(a: array<iterator<auto>>): auto
This function runs all async function until they are finished (in parallel, starting from the last one).
- Arguments:
a : array<iterator<auto>>