Skip to content

Instantly share code, notes, and snippets.

@jdmarshall
Last active June 8, 2016 00:11
Show Gist options
  • Save jdmarshall/e16424c6f039fb6bf4dab1951cb32129 to your computer and use it in GitHub Desktop.
Save jdmarshall/e16424c6f039fb6bf4dab1951cb32129 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
var domain = require('domain');
var Promise = require('bluebird');
console.log('This is a demonstration of a bug in Bluebird when Domains are involved.');
console.log('If a then() throws an exception, the domain does not exit() and remains on the stack.');
function reportDomainDepth(state) {
console.log(state + ', current domain depth is ' + domain._stack.length);
}
var promise;
var resolver;
domain.create().run(function() {
reportDomainDepth('In domain.run()');
promise = new Promise(function(resolve) {
resolver = resolve;
}).then(function() {
reportDomainDepth('Prior to exception');
throw new Error('Here is where the wheels come off');
}).catch(function() {
reportDomainDepth('In exception handler');
});
});
reportDomainDepth('After domain exit');
resolver('asynchronous resolve()');
process.on('exit', function() {
reportDomainDepth('At exit');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment