Re: Would it be possible to add “await on first use” to the language?
Logan Smyth
loganfsmyth at gmail.com
Fri Feb 24 05:23:44 UTC 2017
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.vidas at 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 at 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 at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170223/85a75d8c/attachment-0001.html>
More information about the es-discuss
mailing list