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

Domenic Denicola d at domenic.me
Fri Feb 24 02:51:39 UTC 2017


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.



More information about the es-discuss mailing list