Created
January 15, 2018 19:37
-
-
Save TimothyGu/3a77658df1ff31a9dc28d5fc4c7fa8a8 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! | |
await 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