# async blocks proposal

**URL:** <https://es.discourse.group/t/async-blocks-proposal/422>\
**Category:** 💡 Ideas\
**Created:** [August 8, 2020, 2:02am UTC](https://es.discourse.group/t/async-blocks-proposal/422 "2020-08-08T02:02:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeen3](https://avatars.discourse-cdn.com/v4/letter/z/e79b87/32.png) [@zeen3](https://es.discourse.group/u/zeen3)\
**Post date:** [August 8, 2020, 2:02am UTC](https://es.discourse.group/t/async-blocks-proposal/422/1 "2020-08-08T02:02:53Z")

</div>

Functionality:

```javascript
let prom = async {
  let thing = await fetch("thing");
  await frame();
  await dostuff(thing);
}

```

Would be equivalent to

```javascript
let prom = Promise.resolve().then(async () => {
  let thing = await fetch("thing");
  await frame();
  await dostuff(thing);
});

```

Inspiration: rust async blocks

Usecase: primarily in the service workers `waitUntil` callback, or other places expecting a promise.

This would allow other uses, and may sync well with making `do` a statement that can accept a block; eg `do async {}`.

I'm unsure as to the specifications, but was hoping to gain some interest on it. I'm currently unsure as to whether to use `return`, `yield`, `break`, or `continue` to produce a value; or to disallow returning from it entirely.

Thank you,

-- zeen3.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [August 8, 2020, 12:20pm UTC](https://es.discourse.group/t/async-blocks-proposal/422/2 "2020-08-08T12:20:19Z")

</div>

You'll want to have a look at [https://github.com/zenparsing/proposal-async-block](https://github.com/zenparsing/proposal-async-block) :-) Also see the links in [https://github.com/inexorabletash/ecmascript-async-do-expressions](https://github.com/inexorabletash/ecmascript-async-do-expressions), especially the [_`do` expressions_ proposal](https://github.com/tc39/proposal-do-expressions) which has [multiple](https://github.com/tc39/proposal-do-expressions/issues/38) [issue](https://github.com/tc39/proposal-do-expressions/issues/4) discussions about `async` (`do`) blocks.

---

<div class="post-metadata">

**Author:** ![seekr3](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/seekr3/32/476_2.png) [@seekr3](https://es.discourse.group/u/seekr3)\
**Post date:** [November 5, 2020, 6:26pm UTC](https://es.discourse.group/t/async-blocks-proposal/422/3 "2020-11-05T18:26:14Z")

</div>

I like this. I think they're adding top level await soon which will make it so you don't have to do the first thing as much. Would be nice if you could use something like this so top level await didn't block the app though.

---

<div class="post-metadata">

**Author:** ![pjdebruin64](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/pjdebruin64/32/1008_2.png) [@pjdebruin64](https://es.discourse.group/u/pjdebruin64)\
**Post date:** [September 10, 2021, 9:26am UTC](https://es.discourse.group/t/async-blocks-proposal/422/4 "2021-09-10T09:26:48Z")

</div>

Yes please!  
I so often want to create a Promise using async notation, and end up creating an async function just to call it immediately:

```javascript
let prom = (async () => { *statements* })();

```

E.g., when calling Promise.all(), one has to provide a list of promises, and I find it absurd one is obliged to create functions just to use async/await notation.

Why can't we skip the function creation and write just:

```javascript
let prom = async { *statements* };

```

The result value of the promise should be given by the 'return' statement.
