3 ms·
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
by theprotocol 9y ago
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).
- brn27 9y agoNo, 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.
- theprotocol 9y agoOh. 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.
- brn27 9y agofor-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.