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

2017-02-23 Thread T.J. Crowder
On Fri, Feb 24, 2017 at 5:18 AM, Šime Vidas 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 >

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

2017-02-23 Thread Danielle McLean
On 24 February 2017 at 16:19:03, Šime Vidas (sime.vi...@gmail.com) wrote: > To clarify, the idea is to declare and kick off all the concurrent tasks > upfront Well, that's what promises *already* do, even without using the `async` and `await` keywords. You kick off all concurrent tasks up-front

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

2017-02-23 Thread Logan Smyth
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 =

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

2017-02-23 Thread Šime Vidas
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

Proposal: a more consistent and stricter number converting function - Number.of()

2017-02-23 Thread 段垚
Hi, Converting an arbitray value to a number in JS can be rather inconsistent and unexpected: * `null` and `undefined` are different: `+null === 0` but `+undefined` is NaN. * Empty string and non-nubmeric strings are different: `+"" === 0` but `+"foo"` is NaN. This problem can be

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

2017-02-23 Thread Domenic Denicola
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 =

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

2017-02-23 Thread Šime Vidas
Daniel Brain from PayPal has written a post about async/await: https://medium.com/@bluepnume/even-with-async-await-you-probably-still-need-promises-9b259854c161 It revolves around writing an async function which would execute three tasks in parallel like so: |- dough -> |