Skip to content

Commit

Permalink
remove use of core domain module - due to it being deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjochem committed Aug 22, 2017
1 parent c6491ae commit ba4906d
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions lib/shutdown-coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
'use strict';

var asyncModule = require('async');
var domain = require('domain');
var debug = require('debug')('shutdown');
var debug = require('debug')('shutdown')

function ShutdownCoordinator(options) {
this.handlers = {};
Expand Down Expand Up @@ -80,44 +79,32 @@ ShutdownCoordinator.prototype = {
return function(stageCallback) {
asyncModule.parallel(stageHandlers.map(function(handler) {
return function(handlerCallback) {
var st;

var d = domain.create();
d.on('error', function(err) {
clearTimeout(st);

console.error(handler.name + ' handler failed during shutdown: ' + err);
handlerCallback();
});

d.run(function() {
// Stage timeout
var st = setTimeout(function() {
console.error(handler.name + ' shutdown handler did not complete in a timely manner');
if(handlerCallback) {
handlerCallback();
}
}, stageTimeout);
st.unref();

// Call the handler
try {
debug('Initiating shutdown of %s', handler.name);

handler.handler(function(err) {
if(err) {
console.error(handler.name + ' handler failed during shutdown: ' + err);
}

clearTimeout(st);
handlerCallback();
});
} catch(e) {
clearTimeout(st);
handlerCallback();
// Stage timeout
var st = setTimeout(function() {
console.error(handler.name + " shutdown handler did not complete in a timely manner");
if (handlerCallback) {
handlerCallback();

}
});
}, stageTimeout);
st.unref();

// Call the handler
try {
debug('Initiating shutdown of %s', handler.name);

handler.handler(function(err) {
if(err) {
console.error(handler.name + " handler failed during shutdown: " + err);
}

clearTimeout(st);
handlerCallback();
});
} catch(e) {
clearTimeout(st);
handlerCallback();
}
};
}), function(err) {
/* err should never happen, but anyway */
Expand Down

0 comments on commit ba4906d

Please sign in to comment.