From 97c2e7adc0c6020853677bc1f74261511ef1784b Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 20 Jun 2016 21:05:47 -0600 Subject: [PATCH] Call shutdown() of msg network modules @ shutdown --- core/bbs.js | 7 ++++++- core/msg_network.js | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/core/bbs.js b/core/bbs.js index 1020ee3e..58186af5 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -100,10 +100,15 @@ function shutdownSystem() { }, function stopEventScheduler(callback) { if(initServices.eventScheduler) { - return initServices.eventScheduler.shutdown(callback); + return initServices.eventScheduler.shutdown( () => { + callback(null); // ignore err + }); } else { return callback(null); } + }, + function stopMsgNetwork(callback) { + require('./msg_network.js').shutdown(callback); } ], () => { diff --git a/core/msg_network.js b/core/msg_network.js index 030c544e..9e0813f4 100644 --- a/core/msg_network.js +++ b/core/msg_network.js @@ -5,9 +5,9 @@ let loadModulesForCategory = require('./module_util.js').loadModulesForCategory; // standard/deps -let async = require('async'); +let async = require('async'); -exports.startup = startup +exports.startup = startup; exports.shutdown = shutdown; exports.recordMessage = recordMessage; @@ -36,12 +36,19 @@ function startup(cb) { ); } -function shutdown() { - msgNetworkModules.forEach(mod => { - mod.shutdown(); - }); - - msgNetworkModules = []; +function shutdown(cb) { + async.each( + msgNetworkModules, + (msgNetModule, next) => { + msgNetModule.shutdown( () => { + return next(); + }); + }, + () => { + msgNetworkModules = []; + return cb(null); + } + ); } function recordMessage(message, cb) {