Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active February 7, 2016 21:30
Show Gist options
  • Save domenic/c5c6366e195c00525478 to your computer and use it in GitHub Desktop.
Save domenic/c5c6366e195c00525478 to your computer and use it in GitHub Desktop.
Execution order is broken by proposed module changes
// es6a.js

await foo(); // takes 10 milliseconds

require('./y.js');
// es6b.js

console.log("from es6b");
// cjsa.js

const a = require("es6a.js");
const b = require("es6b.js");
  • If it takes less than 10 milliseconds to retrieve es6b.js from disk, this will evaluate es6a.js, y.js, es6b.js
  • If it takes more than 10 milliseconds to retrieve es6b.js, this will evaluate es6a.js, es6b.js, y.js.

In contrast, with promises (or with equivalent ES6 imports):

// cjsb.js

(async () => {
  const a = await require("es6a.js");
  const b = await require("es6b.js");
})
.catch(console.error);

Evaluation order will always be es6a.js, y.js, es6b.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment