5 ms·
top level await doesn't make async operations synchronous. It mostly eliminates the need to have immediately evaluated wrapper async functions that we would ha
by lf-non 7y ago
top level await doesn't make async operations synchronous.
It mostly eliminates the need to have immediately evaluated wrapper async functions that we would have needed so far.
(async () => {
await foo();
})();
The added benefit is that imported scripts would be implicitly awaited upon, which has been clunky to do otherwise - you'd need to have a module that exposes an async function and expect the consumer to await on them. But the moment you do that you'd no longer be able to directly run the script through node, so you'd end up needing one more file that imports this module and runs it directly.
Availability of top-level await makes experimenting with (promise-returning) APIs in REPL much easier. It is also a bit step forward in making typescript more useful as a general purpose scripting language (outside webdev context).
- hashkb 7y ago> top level await doesn't make async operations synchronous No, it just lets us write them like they look in synchronous languages. So we're jumping through even more hoops to avoid the realities of asynchronous JS. IMO it's better for the asynchrony to be explicit. A whole generation of frontend devs aren't going to have any idea how their code is actually running.