hap*_*set 3 try-catch node.js promise
我创建域并运行它.现在,当输入域时process.domain指向当前活动域.但后来我运行Promise并得到一些奇怪的东西.
'use strict';
var domainCreate = require('domain').create;
var domain = domainCreate();
domain.requestId = 1;
domain.run(function() {
console.log(process.domain === domain); // true
console.log(process.domain.requestId); // 1
Promise.resolve().then(function() {
console.log(process.domain === domain); // false!!!
console.log(process.domain.requestId); // throw new TypeError('Cannot read property 'requestId' of undefined')
}).catch(function(err) {
console.error(err.stack);
});
});
Run Code Online (Sandbox Code Playgroud)
为什么process.domain在Promise链中变得不确定?
| 归档时间: |
|
| 查看次数: |
405 次 |
| 最近记录: |