So you'd be imagining something that would create a variable that would
automatically await when accessed, like
```
async function makePizza(sauceType = 'red') {

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

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

  return dough;
}
```
that would ensure the value is available before accessing them?

On Thu, Feb 23, 2017 at 9:18 PM, Šime Vidas <sime.vi...@gmail.com> wrote:

> 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...@domenic.me> 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.
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to