# What is await\* (with asterisk)?

**URL:** <https://forum.dfinity.org/t/what-is-await-with-asterisk/19887>\
**Category:** Motoko\
**Created:** [May 11, 2023, 6:03am UTC](https://forum.dfinity.org/t/what-is-await-with-asterisk/19887 "2023-05-11T06:03:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [May 11, 2023, 6:03am UTC](https://forum.dfinity.org/t/what-is-await-with-asterisk/19887/1 "2023-05-11T06:03:23Z")

</div>

What is `await*` (with asterisk) in Motoko?

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [May 11, 2023, 6:55am UTC](https://forum.dfinity.org/t/what-is-await-with-asterisk/19887/2 "2023-05-11T06:55:28Z")

</div>

In Motoko, `await*` (with an asterisk) is a keyword used to execute a delayed asynchronous computation that was previously created using the `async*` keyword.

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 `async`/`await` keywords.

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [May 11, 2023, 7:10am UTC](https://forum.dfinity.org/t/what-is-await-with-asterisk/19887/3 "2023-05-11T07:10:07Z")

</div>

Please clarify: `await*` commits state and suspends execution:

- at arbitrary points
- at `await*` and any other points
- at a subset of `await`s?

Also, please help me to understand usual use cases of `await*`. How to decide should I use `await` or `await*`?

Motoko tutorial seems to be silent about `awake*`. Could you point me a tutorial?

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [May 11, 2023, 8:33am UTC](https://forum.dfinity.org/t/what-is-await-with-asterisk/19887/4 "2023-05-11T08:33:29Z")

</div>

The `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 `async*` and `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 `return` or `throw` expressions.
- When explicit `await` expressions are used.
