Async Sandboxes #

const vm = require('vm')
const context = { a: async () => console.log('aaa') }
const code = `await a(); console.log('bbb')`;
new Promise(resolve => {
context.console = console;
context.resolve = resolve;
vm.runInContext(
`(async () => { ${code}; console.log('pre resolve'); resolve() })()`,
vm.createContext(context))
}).then(res => console.log('res', res)).catch(e => console.log('error', e))