Last active
May 24, 2018 13:26
-
-
Save azu/9700273 to your computer and use it in GitHub Desktop.
node vm + domain error handling
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
setTimeout(function () { | |
throw new Error("local error"); | |
},16); |
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
/** | |
* Created by azu on 2014/03/22. | |
* LICENSE : MIT | |
*/ | |
"use strict"; | |
var vm = require("vm"); | |
var fs = require("fs"); | |
var domain = require('domain'); | |
var code = fs.readFileSync(__dirname + "/test/fixtures/async-code.js", "utf-8"); | |
var d = domain.create(); | |
var context = {}; | |
for (var k in global) { | |
context[k] = global[k]; | |
} | |
d.on('error', function (error) { | |
console.log("Error", error.message); | |
}); | |
d.run(function () { | |
vm.runInNewContext(code, context); | |
}); | |
console.log("done"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment