3 ms·
Why doesn't nodejs just make modules async? // main.js const fs = require("fs") const foo = await require_async("foo") await foo.sleep(1000) // oth
by wruza 5y ago
Why doesn't nodejs just make modules async?
// main.js
const fs = require("fs")
const foo = await require_async("foo")
await foo.sleep(1000)
// other.js
require("./main.js")
// RequireError: main.js returned an unsettled promise, use require_async()
Wouldn't that be better of both worlds?
- eyelidlessness 5y agoNode did make modules async (just ESM modules). They can’t/won’t make CJS async because their synchronous semantics are a guarantee they determined not to break well before ESM. If you want async modules, ESM is the solution for that.
- wruza 5y agoESM will be the solution to that, when all the major toolchains catch up. I wouldn't sell this future short, but we aren't there yet either.
- eyelidlessness 5y agoI agree but I think we’re there (if kicking a bit and screaming a bit).