Awaiting block expression

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Awaiting block expression

Tobias Buschor-2
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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Awaiting block expression

Augusto Moura
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
<[hidden email]> 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
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss



--
Atenciosamente,

Augusto Borges de Moura
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Awaiting block expression

Augusto Moura
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
<[hidden email]> 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
> <[hidden email]> 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
> > [hidden email]
> > https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> --
> Atenciosamente,
>
> Augusto Borges de Moura



--
Atenciosamente,

Augusto Borges de Moura
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Awaiting block expression

Colin Cheng
In reply to this post by Tobias Buschor-2
How about like do expression:

```javascript
const image = await (async do {
    const user = await fetch('/user/'+id).json();
    await fetch('/image/'+user.image).json()
})
```
On Jun 21, 2019 14:41, Tobias Buschor <[hidden email]> wrote:

>
> 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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss