5 ms·
I know that the argument that "silly developers shouldn't be allowed to do silly things" is a valid one, but I don't see a convincing argument that top level aw
by thomasfoster96 10y ago
I know that the argument that "silly developers shouldn't be allowed to do silly things" is a valid one, but I don't see a convincing argument that top level await is worse than what developers are currently doing, which is use synchronous functions to do IO at the top level.
If anything, top level async would be an improvement, as it would give developers no reason to do synchronous IO.
Edit: Additionally, ES6 modules are already imperative. There isn't any way to make them declarative.
- dangoor 10y agoES6 modules are declarative in the sense that the dependencies are statically analyzable.
- thomasfoster96 10y agoTrue, but I interpreted the OP as criticising any execution of code on module load (other than declaring exports). Unless loading a file is a bottleneck, which I doubt.
- dangoor 10y ago> Unless loading a file is a bottleneck, which I doubt. Loading a file is a bottleneck in the browser, right?
- thomasfoster96 10y agoRight, but I don't see how top level await makes the current situation any worse. Web developers already have to think about the order of script loading and execution.
- 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.