Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
domain: Wrap destroy methods in a try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 13, 2012
1 parent 7b3fd2e commit 7aeec9d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions lib/domain.js
Expand Up @@ -24,6 +24,9 @@ var events = require('events');
var EventEmitter = events.EventEmitter;
var inherits = util.inherits;

// methods that are called when trying to shut down expliclitly bound EEs
var endMethods = [ 'end', 'abort', 'destroy', 'destroySoon' ];

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
Expand Down Expand Up @@ -198,22 +201,18 @@ Domain.prototype.dispose = function() {
m.on('error', function() {});
}

// call all final methods.
if (typeof m.end === 'function') {
m.end();
}
if (typeof m.abort === 'function') {
m.abort();
}
if (typeof m.close === 'function') {
m.close();
}
if (typeof m.destroy === 'function') {
m.destroy();
}
if (typeof m.destroySoon === 'function') {
m.destroySoon();
}
// Be careful!
// By definition, we're likely in error-ridden territory here,
// so it's quite possible that calling some of these methods
// might cause additional exceptions to be thrown.
endMethods.forEach(function(method) {
if (typeof m[method] === 'function') {
try {
m[method]();
} catch (er) {}
}
});

});

// remove from parent domain, if there is one.
Expand Down

0 comments on commit 7aeec9d

Please sign in to comment.