Can't I already do this by putting a fs.readFileSync call or a synchronous AJAX call in my code?
However, the argument against allowing await in top level code doesn't make much sense if all of these bad side effects already exist.
Again, I don't understand the point of the proposal in this context since nobody should be awaiting a long list of dependencies to load first. If you have 100 dependencies that means you have 100 HTTP requests, which is really a poor design decision. That's why we bundle up dependencies into fewer chunks first before sending them down to the client.
Edit: I understand that this would become a sequential issue if one import leads to a request which leads to further imports which lead to more subsequent requests. My point is that unless the developer(s) really don't understand how async/await works, they wouldn't reasonably design an app like this.
I'm not sure I follow – isn't that the definition of 'dependency'?
> If you have 100 dependencies that means you have 100 HTTP requests, which is really a poor design decision
Agree – and it turns out that's still the case with HTTP2. But bundling doesn't solve the problem of await blocking your app, unfortunately.
Await doesn't actually block the entire app (or JS thread) like synchronous code does. It schedules the code that follows after an await in the same file or in an async function to run later. You probably already understand this, but my point is that other code outside of this context is free to continue running.