Re:Show HN: New async JavaScript paradime with async generat...
by theprotocol on Tuesday June 27, 2017 @01:12AM
(#14642727)
Is the main addition here the scoping of the awaited response? Am I missing something else?
In ES6+ `try/catch` already offers similar scoping, albeit without the destructuring of the result being a part of the syntax (you declare the response, preferably as a `const`, at the top of the try/catch block).
Re:Show HN: New async JavaScript paradime with async generat...
by brn27 on Tuesday June 27, 2017 @01:22AM
(#14642767)
No, scoping is not a matter.
Most important things in here is that you can treat async callback or async repeatation as normal for-await-of loop.
Async callback function is no loger necessary any more in javascript.
Re:Show HN: New async JavaScript paradime with async generat...
by theprotocol on Tuesday June 27, 2017 @01:36AM
(#14642800)
Oh. This is interesting. Is the `for await` loop synchronous, or is more like looping through the results of `Promise.all`? With Promise.all, you can make multiple async concurrently and then await the results once all of them are complete.
Re:Show HN: New async JavaScript paradime with async generat...
by brn27 on Tuesday June 27, 2017 @02:10AM
(#14642891)
for-await loop behavior is bit complex, but roughly, it's like async await functionality. So, for-await loop wait promise step by step, and if await keyword exists in loop body, wait too. So it's looks like synchronous from inside of async function, but behave as asynchronous promise at outside of async function.
In ES6+ `try/catch` already offers similar scoping, albeit without the destructuring of the result being a part of the syntax (you declare the response, preferably as a `const`, at the top of the try/catch block).