await* (with asterisk) in Motoko?
await* (with an asterisk) is a keyword used to execute a delayed asynchronous computation that was previously created using the
await* keyword differs from the regular
await keyword in that it only commits state and suspends execution when necessary in the
await*-ed computation, not necessarily at the
await* itself. This helps to avoid the resource consumption and latency associated with regular
await* commits state and suspends execution:
- at arbitrary points
await*and any other points
- at a subset of
Also, please help me to understand usual use cases of
await*. How to decide should I use
Motoko tutorial seems to be silent about
awake*. Could you point me a tutorial?
async* and corresponding
await* constructs provide an efficient way to abstract asynchronous code into reusable functions. When calling a local function that returns a proper
async type, committing state and suspending execution occur with each
await of its result. This can be an undesirable and inefficient way of handling asynchronous code. By using
await*, the generator-based approach can optimize performance by only suspending and resuming execution when necessary, resulting in more efficient and cleaner code.
The locations where both tentative state changes and message sends become permanently binding are as follows:
- When a shared function produces a result, resulting in an implicit exit.
- When an explicit exit occurs through the use of
- When explicit
awaitexpressions are used.