refactor: no need for async/callbacks

isekai-main
Barış Soner Uşaklı 3 years ago
parent 38756a0c34
commit 057d1d58e3

@ -5,7 +5,6 @@ const fs = require('fs');
const url = require('url'); const url = require('url');
const path = require('path'); const path = require('path');
const { fork } = require('child_process'); const { fork } = require('child_process');
const async = require('async');
const logrotate = require('logrotate-stream'); const logrotate = require('logrotate-stream');
const mkdirp = require('mkdirp'); const mkdirp = require('mkdirp');
@ -36,7 +35,7 @@ const Loader = {
}; };
const appPath = path.join(__dirname, 'app.js'); const appPath = path.join(__dirname, 'app.js');
Loader.init = function (callback) { Loader.init = function () {
if (silent) { if (silent) {
console.log = (...args) => { console.log = (...args) => {
output.write(`${args.join(' ')}\n`); output.write(`${args.join(' ')}\n`);
@ -45,17 +44,15 @@ Loader.init = function (callback) {
process.on('SIGHUP', Loader.restart); process.on('SIGHUP', Loader.restart);
process.on('SIGTERM', Loader.stop); process.on('SIGTERM', Loader.stop);
callback();
}; };
Loader.displayStartupMessages = function (callback) { Loader.displayStartupMessages = function () {
console.log(''); console.log('');
console.log(`NodeBB v${pkg.version} Copyright (C) 2013-2014 NodeBB Inc.`); console.log(`NodeBB v${pkg.version} Copyright (C) 2013-2014 NodeBB Inc.`);
console.log('This program comes with ABSOLUTELY NO WARRANTY.'); console.log('This program comes with ABSOLUTELY NO WARRANTY.');
console.log('This is free software, and you are welcome to redistribute it under certain conditions.'); console.log('This is free software, and you are welcome to redistribute it under certain conditions.');
console.log('For the full license, please visit: http://www.gnu.org/copyleft/gpl.html'); console.log('For the full license, please visit: http://www.gnu.org/copyleft/gpl.html');
console.log(''); console.log('');
callback();
}; };
Loader.addWorkerEvents = function (worker) { Loader.addWorkerEvents = function (worker) {
@ -107,17 +104,13 @@ Loader.addWorkerEvents = function (worker) {
}); });
}; };
Loader.start = function (callback) { Loader.start = function () {
numProcs = getPorts().length; numProcs = getPorts().length;
console.log(`Clustering enabled: Spinning up ${numProcs} process(es).\n`); console.log(`Clustering enabled: Spinning up ${numProcs} process(es).\n`);
for (let x = 0; x < numProcs; x += 1) { for (let x = 0; x < numProcs; x += 1) {
forkWorker(x, x === 0); forkWorker(x, x === 0);
} }
if (callback) {
callback();
}
}; };
function forkWorker(index, isPrimary) { function forkWorker(index, isPrimary) {
@ -232,15 +225,12 @@ fs.open(pathToConfig, 'r', (err) => {
fs.writeFileSync(pidFilePath, String(process.pid)); fs.writeFileSync(pidFilePath, String(process.pid));
} }
try {
async.series([ Loader.init();
Loader.init, Loader.displayStartupMessages();
Loader.displayStartupMessages, Loader.start();
Loader.start, } catch (err) {
], (err) => {
if (err) {
console.error('[loader] Error during startup'); console.error('[loader] Error during startup');
throw err; throw err;
} }
}); });
});

Loading…
Cancel
Save