From ba4906d812a5b954ce1c9150ceceb45c02150d8a Mon Sep 17 00:00:00 2001 From: Jochem Maas Date: Thu, 23 Mar 2017 12:28:14 +0100 Subject: [PATCH] remove use of core domain module - due to it being deprecated --- lib/shutdown-coordinator.js | 63 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/lib/shutdown-coordinator.js b/lib/shutdown-coordinator.js index 6240a89..9cceadc 100644 --- a/lib/shutdown-coordinator.js +++ b/lib/shutdown-coordinator.js @@ -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 = {}; @@ -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 */