Skip to content

Instantly share code, notes, and snippets.

@TimothyGu
Created January 15, 2018 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimothyGu/f02096b2f31d62a63e414fe283c8efac to your computer and use it in GitHub Desktop.
Save TimothyGu/f02096b2f31d62a63e414fe283c8efac to your computer and use it in GitHub Desktop.
'use strict';
const { Module } = require('vm');
process.on('unhandledRejection', p => {
process.nextTick(() => { throw p; });
});
(async () => {
const rootModule = new Module('export default 5;');
const slowModule = new Module(`import five from 'root'; export default five;`);
const topModule = new Module(`import five from 'slow'; console.log(five);`);
await rootModule.link(() => {});
// This is never awaited!
slowModule.link(() => new Promise((resolve, reject) => {
setTimeout(resolve, 1000, rootModule);
}));
await topModule.link(() => slowModule);
topModule.instantiate();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment