188 karma · joined May 30, 2016
> import foo from 'foo';
> await foo.bar();
You only have to `await foo.bar()` if foo.bar was an async function already, the module system is irrelevant. You would still need to await it even if it was `require()`'d in. import baz from 'baz';
baz.foo();
Works just fine, no `await` necessary. > await Promise.all([
> import('other'),
> import('stuff'),
> ]);
Of course these have to be awaited, at this point you're explicitly trying to load new code while the program is running. It's no different than any other kind of async IO. > import yet from 'more-stuff';
I assume this is included to imply that loading `yet` is blocked by the `await Promise.all` above it to show that import statements can run after module resolution. If this was your intent you are mistaken, that import statement is still resolved before execution begins. // main.js
console.log('a')
await new Promise(res => setTimeout(res, 1000))
console.log('b')
import { foo } from "./foo.js";
// foo.js
export function foo() {
}
console.log('c')
Results in c
a
[one second pause]
b
> Yes, an import statement is [semantically] blocking. But even so it’s important to know that it’s performing async I/O.No, it really isn't. From the POV of the application code it's irrelevant. This is trivially proven by the existence of module bundlers which convert non-dynamic `import` statements into one big file that doesn't do anything asynchronous to initialize.
(edit: fighting with formatting)
> ...nobody could be bothered to develop a nationwide program to test people for infection and trace their contacts if they were positive, or to adequately support a pause of economic activity...
As for nationwide program to test people, of course nothing was built yet; it's a novel virus and therefore novel tests are needed. If a government had built out contact tracing pre-covid, they would be (rightly) criticized for taking steps in an authoritarian direction. Apple and Google have stepped in and built contact tracing, so to say this hasn't been developed is also factually inaccurate. Finally the comment about the ability to "adequately support a pause of economic activity" is kind of silly. To pause economic activity is to pause everyone's lives. What does it mean to adequately support people when they're no longer allowed to do the things they enjoy?
It was a breath of fresh air to read an article that admitted that this is a difficult trade off, not some kind of easy decision that's being ruined by the other guy. It was disappointing that it was concluded with a similar tone.