# Async property accessor: -\>

**URL:** <https://es.discourse.group/t/async-property-accessor/765>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [May 4, 2021, 4:40pm UTC](https://es.discourse.group/t/async-property-accessor/765 "2021-05-04T16:40:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielWeiner](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/danielweiner/32/804_2.png) [@DanielWeiner](https://es.discourse.group/u/DanielWeiner)\
**Post date:** [May 4, 2021, 4:40pm UTC](https://es.discourse.group/t/async-property-accessor/765/1 "2021-05-04T16:40:24Z")

</div>

The idea is to access a property of an awaited value to allow deep chaining of async operations.

Right now, to accomplish that kind of chaining you need to write:

```javascript
const baz = await (await (await fetchFoo()).fetchBar()).fetchBaz();

```

That can get pretty awkward pretty fast. My idea is a new operator that accomplishes this without all the nested parens:

```javascript
const baz = await fetchFoo()->fetchBar()->fetchBaz();

```

Additionally, they can be optionally chained like the other property accessors:

```javascript
const baz = await fetchFoo()?->fetchBar()?->fetchBaz();

```

I figured that `->` seems appropriate for a new property accessor operator, as it's used by other languages like C++ as a way to access a property.

This operator would only be available in an async scope, since it's essentially a shorthand for `await`.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [May 4, 2021, 4:53pm UTC](https://es.discourse.group/t/async-property-accessor/765/2 "2021-05-04T16:53:46Z")

</div>

See [https://github.com/tc39/proposal-wavy-dot](https://github.com/tc39/proposal-wavy-dot)

---

<div class="post-metadata">

**Author:** ![DanielWeiner](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/danielweiner/32/804_2.png) [@DanielWeiner](https://es.discourse.group/u/DanielWeiner)\
**Post date:** [May 4, 2021, 5:08pm UTC](https://es.discourse.group/t/async-property-accessor/765/3 "2021-05-04T17:08:36Z")

</div>

Wonderful! I'm seeing now that it's in stage 1. That syntax would be amazing. Fingers crossed!

---

<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:47pm UTC](https://es.discourse.group/t/async-property-accessor/765/4 "2023-01-09T17:47:36Z")

</div>

I would love to see this feature out, my class has almost all of the methods are async, and parentheses+await don't look readable after a few chain steps. bravo!

Arrow is nicer than tilde+dot, arrow is a more common syntax.

---

<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:39pm UTC](https://es.discourse.group/t/async-property-accessor/765/5 "2023-01-13T16:39:41Z")

</div>

Wavy dot is meant as a syntax tool to help with [eventual-send](https://github.com/tc39/proposal-eventual-send). The major difference between what is suggested here and eventual-send is pipelining. In a single agent there is no difference, but in distributed systems (e.g. between Workers, or between a client and server), you want to avoid paying the round trip costs, which here would occur because of the intermediary `await`s.

To take the above example, you want to send as soon as possible `fetchBaz()` to the result of `fetchBar()` which was itself send to the result of `fetchFoo()`. You only want to await the result of `fetchBaz()`. Results are represented by promises, and sending a message to a promise means sending the message to the system that is currently in charge of deciding that promise.

These proposals are a little stale, but Agoric has been using these mechanisms for years. `eventual-send` has a [shim in the endo repository](https://github.com/endojs/endo/tree/master/packages/eventual-send), which uses a `E` helper in place of the `~.` syntax. The developer documentations are lacking / out of date, and I believe there is a strong dependency of the eventual-send package on SES for now. There is a [Matrix room](https://matrix.to/#/!HsYbIBNVuGCAlAfixO:matrix.org?via=matrix.org) where you may be able to get some questions answered.

Btw, the pipeline operator will probably be a good approximation of the benefits of wavy-dot, at least until that kind of distributed patterns emerges more fully.

With `await`:

```javascript
const baz = await fetchFoo() |> await %.fetchBar() |> await %.fetchBaz();

```

With `E`:

```javascript
const baz = await (fetchFoo() |> E(%).fetchBar() |> E(%).fetchBaz());

```

With wavy-dot:

```javascript
const baz = await fetchFoo()~.fetchBar()~.fetchBaz();

```

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [January 19, 2023, 6:57am UTC](https://es.discourse.group/t/async-property-accessor/765/6 "2023-01-19T06:57:56Z")

</div>

Correct me if I'm wrong, but isn't the default pipelining operation basically just what's requested above (modulo timings) with the hypothetical `->` operator?

---

<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 19, 2023, 12:18pm UTC](https://es.discourse.group/t/async-property-accessor/765/7 "2023-01-19T12:18:53Z")

</div>

Correct. Sorry if I wasn't clear, but by default eventual-send falls back awaiting non-delegated promises. In a local only environment there is no difference with with the requested feature here.
