Šime Vidas (2017-02-24T02:36:23.000Z)
Daniel Brain from PayPal has written a post about async/await:
https://medium.com/@bluepnume/even-with-async-await-you-probably-still-need-promises-9b259854c161

It revolves around writing an async function which would execute three
tasks in parallel like so:

|--------- dough --------->
|---- sauce ----> |-- cheese -->

The code used as a starting point was:

async function makePizza(sauceType = 'red') {

  let dough  = await makeDough();
  let sauce  = await makeSauce(sauceType);
  let cheese = await grateCheese(sauce.determineCheese());

  dough.add(sauce);
  dough.add(cheese);

  return dough;
}

This pattern, of course, cases the tasks to execute in sequence, like so:

|-------- dough --------> |-------- sauce --------> |-- cheese -->

The remainder of the post introduces several solutions in an attempt to
achieve optimal concurrency. For instance, the author’s preferred solution
uses a custom memoize function and Promise.all.

Compared to the initial code above, these solutions seem complex, almost as
if the language does not have the appropriate syntactic forms and/or APIs
to address this particular use case.

This got me thinking. What if there was a version of await that doesn’t
pause execution on the spot, but continues execution until the variable
which the await is assigned to, is first referenced?

I’ve added comments to mark the positions where execution pauses:

async function makePizza(sauceType = 'red') {

  let dough  = await makeDough();
  let sauce  = await makeSauce(sauceType);
  let cheese = await grateCheese(/* pause to await sauce */
sauce.determineCheese());

  /* pause to await dough */ dough.add(sauce);
  dough.add(/* pause to await cheese */ cheese);

  return dough;
}

Please let me know if adding a await-like keyword that works like this
would be a bad idea. From a layman’s perspective, it seems that having this
feature would simplify code patterns which involve execution in parallel
like the example described in the article.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170224/f1e7cacf/attachment.html>
tj.crowder at farsightsoftware.com (2017-02-24T05:29:04.318Z)
Daniel Brain from PayPal has written a post about async/await:
https://medium.com/@bluepnume/even-with-async-await-you-probably-still-need-promises-9b259854c161

It revolves around writing an async function which would execute three
tasks in parallel like so:

```
|--------- dough --------->
|---- sauce ----> |-- cheese -->
```

The code used as a starting point was:

```js
async function makePizza(sauceType = 'red') {

  let dough  = await makeDough();
  let sauce  = await makeSauce(sauceType);
  let cheese = await grateCheese(sauce.determineCheese());

  dough.add(sauce);
  dough.add(cheese);

  return dough;
}
```

This pattern, of course, cases the tasks to execute in sequence, like so:

```
|-------- dough --------> |-------- sauce --------> |-- cheese -->
```

The remainder of the post introduces several solutions in an attempt to
achieve optimal concurrency. For instance, the author’s preferred solution
uses a custom memoize function and Promise.all.

Compared to the initial code above, these solutions seem complex, almost as
if the language does not have the appropriate syntactic forms and/or APIs
to address this particular use case.

This got me thinking. What if there was a version of await that doesn’t
pause execution on the spot, but continues execution until the variable
which the await is assigned to, is first referenced?

I’ve added comments to mark the positions where execution pauses:

```js
async function makePizza(sauceType = 'red') {

  let dough  = await makeDough();
  let sauce  = await makeSauce(sauceType);
  let cheese = await grateCheese(/* pause to await sauce */sauce.determineCheese());

  /* pause to await dough */ dough.add(sauce);
  dough.add(/* pause to await cheese */ cheese);

  return dough;
}
```

Please let me know if adding a await-like keyword that works like this
would be a bad idea. From a layman’s perspective, it seems that having this
feature would simplify code patterns which involve execution in parallel
like the example described in the article.