3 ms·
> If anything, top level async would be an improvement, as it would give developers no reason to do synchronous IO. Top-level async would make asynchronous IO
by rich_harris 10y ago
> If anything, top level async would be an improvement, as it would give developers no reason to do synchronous IO.
Top-level async would make asynchronous IO no different from synchronous IO! It's the worst of both worlds.
> the dependencies are statically analyzable
Exactly – which means modules can be loaded concurrently, without having to execute the code. By contrast, imperative loading has to happen sequentially. I explored this aspect of it in a follow-up: https://gist.github.com/Rich-Harris/41e8ccc755ea232a5e7b88dee118bcf5 https://gist.github.com/Rich-Harris/41e8ccc755ea232a5e7b88de...
- domenicd 10y ago> Top-level async would make asynchronous IO no different from synchronous IO! It's the worst of both worlds. That's false. You could still do plenty of things while this asynchronous I/O is happening (including allowing the user to interact with the page, or load other modules in the background). > By contrast, imperative loading has to happen sequentially. Yes, but notably, declarative loads are not blocked on imperative loads.
- thomasfoster96 10y ago> Top-level async would make asynchronous IO no different from synchronous IO! It's the worst of both worlds. No it's not. Synchronous IO blocks everything. Asynchronous IO with top level await would still allow things queued in the event loop to execute. Plus, top level await + Promise.all would allow you to do operations concurrently, something that synchronous doesn't.