# bang await chaining operator

**URL:** <https://es.discourse.group/t/bang-await-chaining-operator/940>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [August 21, 2021, 10:22pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940 "2021-08-21T22:22:47Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [August 21, 2021, 10:22pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/1 "2021-08-21T22:22:47Z")

</div>

```javascript
// this is verbose
const response = await fetch('/posts')
const posts = await response.json()

// chaining multiple await expressions in one line is awkward
const posts = await (await fetch('/posts')).json()

// proposal: chain together multiple awaits with !.
const posts = await fetch('/posts')!.json()

```

---

<div class="post-metadata">

**Author:** ![lightmare](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/lightmare/32/843_2.png) [@lightmare](https://es.discourse.group/u/lightmare)\
**Post date:** [August 21, 2021, 11:19pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/2 "2021-08-21T23:19:17Z")

</div>

This has been dubbed the [wavy dot](https://github.com/tc39/proposal-wavy-dot)

```javascript
await fetch('/posts')~.json();

```

---

<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:** [August 21, 2021, 11:30pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/3 "2021-08-21T23:30:52Z")

</div>

Awesome, glad this idea already has some notoriety.

---

<div class="post-metadata">

**Author:** ![dandeancook](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/dandeancook/32/1606_2.png) [@dandeancook](https://es.discourse.group/u/dandeancook)\
**Post date:** [January 9, 2023, 5:45pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/4 "2023-01-09T17:45:16Z")

</div>

The arrow proposal seems nicer, in chaining commonly there are dot and arrow: [Async property accessor: -\>](https://es.discourse.group/t/async-property-accessor/765)

---

<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:** [January 11, 2023, 5:01am UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/5 "2023-01-11T05:01:00Z")

</div>

I’ve just decided in the mean time, while async chaining does not exist, to use just intermediate variables. The double await just looks bad to me.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [January 11, 2023, 7:10am UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/6 "2023-01-11T07:10:50Z")

</div>

I personally like to just use the `.then()` method instead of a double-await.

```javascript
const someResource = fetch('something')
  .then(response => response.json())

```

---

<div class="post-metadata">

**Author:** ![mhofman](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mhofman](https://es.discourse.group/u/mhofman)\
**Post date:** [January 13, 2023, 4:52pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/7 "2023-01-13T16:52:18Z")

</div>

As I explained in [Async property accessor: -\> - #5 by mhofman](https://es.discourse.group/t/async-property-accessor/765/5), wavy dot is meant to enable avoiding intermediary `await`, allowing to pipeline the operations when they are performed on a remote system.

If operations execute in a single JS agent, then there is no difference with explicit awaiting, and the eventual-send effectively does that since the promise is decided locally.

The pipeline operator may help tidying the nested aspect without a new dedicated operator:

```javascript
const posts = await fetch('/posts') |> await %.json();

```

---

<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:** [January 14, 2023, 1:44pm UTC](https://es.discourse.group/t/bang-await-chaining-operator/940/8 "2023-01-14T13:44:54Z")

</div>

That sounds a bit more advanced than an everyday use case.

I think my opinion on this API has changed a little. The main place I wanted it was on the fetch API, but since fetch doesn't fail when the request fails, I prefer to just handle the response.

```javascript
const response = await fetch('/get')

if (!response.ok) throw new Error('Request failed')

const data = await response.json()

```
