Hacker News new | ask | show | jobs
by tiglionabbit 2457 days ago
Do we really want slow imports though? If you have a bunch of modules with async setup functions, would you not be able to Promise.all() them?
2 comments

That kinda stuff is typically an antipattern in C#; an async static "factory method" would be used(I use this pattern myself in Typescript). But I guess JavaScript has odd stuff like code chunking so the importau be pulling remote code and etc.
Sure, in many situations, but I guess if you need to setup things have have dependencies (init A then init B then init C) this will help.
How so? I'm not seeing the benefit over exporting A, B, and C as functions, and then putting them together in another spot (like a composite root for pure DI, or an IoC container, etc).

Is the argument for top-level await that you don't need the other spot? Because I feel like you still do - except now it's implicitly inside not only A, but likely B and C as well to some extent. And in a very inflexible way.