Awaiting block expression

Augusto Moura augusto.borgesm at gmail.com
Fri Jun 21 14:19:12 UTC 2019


Actually... You are proposing a `await` in a block, and a implicit
await in all Promile-like expressions (or every expression) in the
block, that's a totally different beast

I don't think the implicit await part can be easily implemented
neither is a good idea, the code flow can get really confusing,
imagine the following:

``` js
const foo = await {
  const bar = {
    then(callback) {
    },
  };
  return bar;
}
```

What should be the result? Translating your proposal to already valid
code it should be:

``` js
const foo = await (async function() {
  const bar = await {
    then(callback) {
    },
  };
  return bar;
}());
```

Foo will never be resolved, because the awaited `bar` object never
calls the callback argument, and the whole block stagnates waiting for
something that will never happen

Em sex, 21 de jun de 2019 às 10:40, Augusto Moura
<augusto.borgesm at gmail.com> escreveu:
>
> The do expressions proposal[1] had some discussions about having a
> `async` variant[2] you should give it a look
> Is the same concept you are proposing
>
> [1]: https://github.com/tc39/proposal-do-expressions
> [2]: https://github.com/tc39/proposal-do-expressions/issues/4
>
> Em sex, 21 de jun de 2019 às 03:42, Tobias Buschor
> <tobias.buschor at shwups.ch> escreveu:
> >
> > As there are more and more async apis, i would like to have a block, where all promises within automaticly are awaited:
> >
> > Proposal:
> >
> > const image = await {
> >     const user = fetch('/user/'+id).json();
> >     fetch('/image/'+user.image).json();
> > }
> >
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> --
> Atenciosamente,
>
> Augusto Borges de Moura



-- 
Atenciosamente,

Augusto Borges de Moura


More information about the es-discuss mailing list