News for hackers. Stuff that matters.
Re:V8 adds support for top-level await by h8hawk on Tuesday September 24, 2019 @09:56PM (#21066815)
No it's not. async/await's semantic is similar to coroutines, and is implemented by them.
Re:V8 adds support for top-level await by ihuman on Tuesday September 24, 2019 @10:57PM (#21067162)
Are you sure? From what I can find, async [0] causes a function to a return a promise, which then returns the result. Await [1] takes a promise, and waits for it to either be resolved or rejected.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:V8 adds support for top-level await by matt-attack on Tuesday September 24, 2019 @11:46PM (#21067414)
> and waits for it

Yes but that doesn’t mean other lines of code can’t be executing while waiting. The waiting isn’t truly blocking the entire application. Plenty of other things can be happening.

Re:V8 adds support for top-level await by nemetroid on Wednesday September 25, 2019 @07:33AM (#21069681)
Sure, but the next line of the function awaiting the result can't execute while waiting.
Re:V8 adds support for top-level await by h8hawk on Wednesday September 25, 2019 @12:35AM (#21067639)
from your first link: "... , async/await is similar to combining generators and promises."
Re:V8 adds support for top-level await by s_tec on Wednesday September 25, 2019 @02:02AM (#21068093)
It is true that async functions work similarly to the coroutines found in other languages, and that some transpilers convert async functions into Javascript generator functions under the hood. However, these are both implementation details.

On the flip side, there is a Javascript transpiler called nodent which directly converts async functions into the corresponding `Promise.then` calls, with no generators in sight. This transpiler actually generates smaller & faster output than the standard generator-based approaches, since the async/await semantics map more directly to promises.

In other words, async functions really are semantic sugar for promises, even if they have some similarities to coroutines / generators.

To try it yourself, just go to http://nodent.mailed.me.uk/ , check the "spec compliant" option, and look at the generated output.

Re:V8 adds support for top-level await by gitgud on Wednesday September 25, 2019 @01:16AM (#21067836)
Maybe provide some evidence of this, I've also understood them as syntactic sugar for Promises.

Although I have found that babel does seem to transpile them differently to Promises