Created
January 15, 2018 19:37
-
-
Save TimothyGu/f02096b2f31d62a63e414fe283c8efac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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