enigma-bbs/core/msg_network.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

/* jslint node: true */
'use strict';
// ENiGMA½
let loadModulesForCategory = require('./module_util.js').loadModulesForCategory;
// standard/deps
let async = require('async');
exports.startup = startup
exports.shutdown = shutdown;
exports.recordMessage = recordMessage;
let msgNetworkModules = [];
function startup(cb) {
async.series(
[
function loadModules(callback) {
loadModulesForCategory('scannerTossers', (err, module) => {
if(!err) {
const modInst = new module.getModule();
modInst.startup(err => {
if(!err) {
msgNetworkModules.push(modInst);
}
});
}
}, err => {
callback(err);
});
}
],
cb
);
}
function shutdown() {
msgNetworkModules.forEach(mod => {
mod.shutdown();
});
msgNetworkModules = [];
}
function recordMessage(message, cb) {
//
// Give all message network modules (scanner/tossers)
// a chance to do something with |message|. Any or all can
// choose to ignore it.
//
async.each(msgNetworkModules, (modInst, next) => {
modInst.record(message);
next();
}, err => {
cb(err);
});
}