Skip to content

Instantly share code, notes, and snippets.

@azu azu/async-code.js
Last active May 24, 2018

Embed
What would you like to do?
node vm + domain error handling
setTimeout(function () {
throw new Error("local error");
},16);
/**
* 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
You can’t perform that action at this time.