Re:V8 adds support for top-level await
by tedivm on Tuesday September 24, 2019 @05:54PM
(#21065034)
Now if only python would do the same.
[ Parent
| on HN ]
Re:V8 adds support for top-level await
by xtreak29 on Wednesday September 25, 2019 @12:08AM
(#21067509)
Top level awaits are allowed with a compiler flag now in Python 3.8 : https://bugs.python.org/issue34616
python -m asyncio
Starts a new repl with the compiler flag to explore top level await in a repl
Re:V8 adds support for top-level await
by iikoolpp on Tuesday September 24, 2019 @06:25PM
(#21065286)
Impossible due to how async is implemented (as generators).
JS async is implemented as generators as well AFAIK
I'm not sure how they're handled internally, but async functions are no longer generators. For a while after generators and before async/await, generators were used as a polyfill.
Re:V8 adds support for top-level await
by pitaj on Wednesday September 25, 2019 @12:05AM
(#21067501)
Because of how similar they are, it would make sense to implement async/await using existing generator backends in the VM, right?
Re:V8 adds support for top-level await
by dlbucci on Tuesday September 24, 2019 @08:16PM
(#21066206)
Not unless promises are implemented with generators. I dunno though, I feel like there's some overlap between the two concepts, so maybe they are?
Promises are just objects which represent an asynchronous value.
Async/await are coroutines: they have a shared context, stack, etc. They can be paused and resumed.
The implementation of async/await depends on the engine, but I'm pretty sure they use the same generator backend.
Babel and other transpilers convert async functions actual generator functions. By contrast, promises are a fairly simple runtime library.