Re: Would it be possible to add “await on first use” to the language?

Šime Vidas sime.vidas at
Fri Feb 24 05:18:49 UTC 2017

To clarify, the idea is to declare and kick off all the concurrent tasks
upfront (using local variables and the ‘lazy await’ keyword), and then just
continue writing the rest of the code ‘as if all the promises are
resolved’. The async function automagically pauses whenever needed, so it’s
no longer necessary to insert await operators throughout the code.

I admit, this is wishful thinking. I’m just waiting for someone to tell me
that it’s not feasible or that it would lead to some very bad code patterns

On Fri, Feb 24, 2017 at 3:51 AM, Domenic Denicola <d at> wrote:

> We already have that feature in the language: it’s called await. Just
> rewrite the example like so, instead of using /* pause to await x */
> comments:
> async function makePizza(sauceType = 'red') {
>   let dough  = makeDough();
>   let sauce  = await makeSauce(sauceType);
>   let cheese = grateCheese(sauce.determineCheese());
>   dough = await dough;
>   dough.add(sauce);
>   dough.add(await cheese);
>   return dough;
> }
> This way, instead of random punctuation like the "." operator causing your
> program to await... it's the actual await keyword.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list