# Inlining await for decreasing the number of checkpoints

**URL:** <https://forum.dfinity.org/t/inlining-await-for-decreasing-the-number-of-checkpoints/19977>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [May 14, 2023, 2:43am UTC](https://forum.dfinity.org/t/inlining-await-for-decreasing-the-number-of-checkpoints/19977 "2023-05-14T02:43:46Z")\
**Posts on this page:** 3\
**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 14, 2023, 2:43am UTC](https://forum.dfinity.org/t/inlining-await-for-decreasing-the-number-of-checkpoints/19977/1 "2023-05-14T02:43:46Z")

</div>

Consider this code:

```plaintext
func f(): Async () {
  // ...
};

func g(): Async () {
  await f();
};

func h(): Async () {
  await g();
};

```

During execution of `g`, `await` is hit twice. So, if I understand correctly, there are two “checkpoints” where the state can be changed by another “thread”.

But the code for `h` is “equivalent” to:

```plaintext
func f(): Async () {
  // ...
};

func h(): Async () {
  await f();
};

```

where we have just one checkpoint.

If I want to decrease the quantity of checkpoints, is there any better solution than to inline function code? (that `// ...` in `f`)

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [May 14, 2023, 5:00am UTC](https://forum.dfinity.org/t/inlining-await-for-decreasing-the-number-of-checkpoints/19977/2 "2023-05-14T05:00:28Z")

</div>

Yes, there is this solution:

```auto
func f() : async () {
 // ..
};

func g() : async* () {
  await f();
};

func h() : async* () {
  await* g();
};

```

I remember there was a good, lengthy explanation in the release notes (or somewhere else on github) when this was introduced, in moc 0.7.4. But now I don’t find it anymore. The release notes for 0.7.4. are brief. Must have been somewhere else on github but I can’t find it.

async\* await\* is of course explained in the language manual: [Internet Computer Loading](https://internetcomputer.org/docs/current/motoko/main/language-manual/)

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [May 14, 2023, 12:54pm UTC](https://forum.dfinity.org/t/inlining-await-for-decreasing-the-number-of-checkpoints/19977/3 "2023-05-14T12:54:36Z")

</div>

Also see [Star.mo - Dealing with async\* - A Library](https://forum.dfinity.org/t/star-mo-dealing-with-async-a-library/19554) for a library to kelp you track if your check point was hit or not.

When an async\* returns you won’t know if a checkpoint triggered or not unless you mange it. I recommend never calling async\* unless it returns this(or similar) structure. of course if you ALWAYS await this isn’t the case…but any branches induce a safety issue.
