Добавлен модуль AsyncExit для выполненния cleanup-процедур перед выходом из приложения

This commit is contained in:
Book Pauk
2021-11-24 14:13:13 +07:00
parent b1e3d33694
commit 4852c7aec3
5 changed files with 179 additions and 73 deletions

View File

@@ -7,6 +7,11 @@ const compression = require('compression');
const http = require('http');
const WebSocket = require ('ws');
const ayncExit = new (require('./core/AsyncExit'))();
ayncExit.init();
let log = null;
async function init() {
//config
const configManager = new (require('./config'))();//singleton
@@ -18,7 +23,7 @@ async function init() {
//logger
const appLogger = new (require('./core/AppLogger'))();//singleton
await appLogger.init(config);
const log = appLogger.log;
log = appLogger.log;
//dirs
log(`${config.name} v${config.version}, Node.js ${process.version}`);
@@ -96,13 +101,15 @@ async function main() {
}
}
(async() => {
try {
await init();
await main();
} catch (e) {
console.error(e);
process.exit(1);
if (log)
log(LM_FATAL, e);
else
console.error(e);
ayncExit.exit(1);
}
})();
})();