3 ms·
Whether or not it's a module or something else being awaited isn't the problem. The issue that if your app.js (or whatever) has dependencies on modules with top
by rich_harris 10y ago
Whether or not it's a module or something else being awaited isn't the problem. The issue that if your app.js (or whatever) has dependencies on modules with top-level awaits, however far removed, it can't execute until they're done. In other words top-level await essentially blocks your entire app.
Using await inside an explicitly async function is great, because it only blocks code inside that function – the effects are localised and much easier to predict/reason about.
- johnhenry 10y agoAh, thank you, that makes sense. The term "footgun" is pretty interesting here, as it generally refers to something that allows one to shoot one's self in the foot. In this case, it's allows someone else to shoot you in the foot by hiding it in their code :/.
- rimunroe 10y agoOn the subject of whether or not this is really a problem because people can just be educated not to do this, the author said: > You'll educate some of them, but not all. If you give people tools like with, eval, and top-level await, they will be misused, with bad consequences for users of the web. This is still a footgun, because it makes it easy for people to introduce wide ranging and sometimes subtle bugs in their software.
- Bartweiss 10y agoAnd as we all know, what JS is missing is a new way for unknowing devs to build slow and buggy products.
- jbpetersen 10y agoNow we just need asynchronous imports and all is well again. I can't even tell whether I'm being sarcastic or not.
- jessaustin 10y agoPresumably you'll be able to tell at some point in future?