function Request(type, name, root) { this.children = []; this.name = name; this.type = type; if (root === true) { var reqDomain = domain.create(); reqDomain.enter(); } if (process.domain) { this.parent = process.domain.currentRequest; } this.id = nextEventId; ++nextEventId; if (this.parent) { this.top = this.parent.top; this.parent.children.push(this); } else { this.top = this; if (this.type) { /* If we're the top and we're a type, we get a request Id, not an event Id */ this.id = nextRequestId; ++nextRequestId; } } }
// 隐式绑定 domain2.run(function(){ var emitter2 = new EventEmitter(); emitter2.emit('error',new Error('通过 domain2 处理')); });
d.once('error', function (err: Error) { console.error(err.stack || err); _suman.writeTestError(err.stack || err); d.exit(); process.nextTick(function () { err = new Error('Suman usage error => Error acquiring IOC deps => \n' + (err.stack || err)); err.sumanFatal = true; err.sumanExitCode = constants.EXIT_CODES.IOC_DEPS_ACQUISITION_ERROR; _suman.log.error(err.stack || err); gracefulExit(err, null); }); });
function bindToCurrentDomain(callback) { if (!callback) { return undefined; } var domain = process.domain; return domain ? domain.bind(callback) : callback; }
d1.on('error', function (err) { assert.equal(err.toString(), 'Error: inside domain 1'); done(); });
d.once('error', function (err: Error) { console.error('\n'); _suman.log.error(chalk.magenta('fatal error => ' + (err.stack || err) + '\n')); process.exit(constants.RUNNER_EXIT_CODES.UNEXPECTED_FATAL_ERROR); });
d.run(() => { changeCWDToRootOrTestDir(projectRoot); if (sumanOpts.rand) { files = shuffle(files); } _suman.sumanSingleProcessStartTime = Date.now(); require('./run-child-not-runner').run(su.removeSharedRootPath(files)); })
scriptDomain.on('error', function (e) { if (!e.stack) { log.error.apply(log, [name + ' unkown exception']); return; } let lines = e.stack.split('\n'); let stack = []; for (let i = 0; i < lines.length; i++) { if (lines[i].match(/\[as runInContext\]/)) break; stack.push(lines[i]); } log.error.apply(log, [name + ' ' + stack.join('\n')]); });
domain1.on('error', function(err){ console.log("domain1 处理这个错误 ("+err.message+")"); });
scriptDomain.run(() => { log.debug(name, 'running'); script.runInContext(context); });
d.run(() => { changeCWDToRootOrTestDir(files[0]); require('./run-child-not-runner').run(files); })
scriptDomain.run(function () { log.debug(name, 'running'); script.runInContext(context); });
domain2.on('error', function(err){ console.log("domain2 处理这个错误 ("+err.message+")"); });
d0.on('error', function (err) { assert.equal(err.toString(), 'Error: inside domain 0'); done(); });