I create domain and run it. Now while domain is entered process.domain
points to current active domain. But then I run Promise and get something strange.
'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);
});
});
Why process.domain
becomes undefined inside Promise chain?