Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove use of [core] domain module - due to it being deprecated #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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