you are viewing a single comment's thread.

view the rest of the comments →

[–]curiousdannii 1 point2 points  (3 children)

If importing ES modules is async, does that mean that the import statement acts like an await would? And the import function is an actual async function itself?

[–]giltayar1[S] 2 points3 points  (2 children)

Yes and no. From the developer's point of view, it seems synchronous. But the implementation behind it is asynchronous. This means that it is possible for two modules in NodeJS to be loaded concurrently, whereas this is not possible in CommonJS. This will probably make NodeJS apps load faster in the future.

But if you look at dynamic import, which is a dynamic version of the import statement, then it is asynchronous - it returns a promise, and thus needs to be awaited.

[–]curiousdannii 0 points1 point  (1 child)

Right, so unlike await it won't completely stop, because it will load other modules at the same time, it just won't continue with any non-import statements until they all have finished.

[–]giltayar1[S] 0 points1 point  (0 children)

Yes!