Wrap entry into async function

This commit is contained in:
April John 2023-10-07 16:21:09 +02:00 committed by GitHub
parent 3d15f89638
commit 447399eb07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,8 +27,11 @@ const logger = new Logger('core', 'cyan');
const clusterLogger = logger.createSubLogger('cluster', 'orange', false); const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
const ev = new Xev(); const ev = new Xev();
//#region Events // We wrap this in a main function, that gets called,
// because not all platforms support top level await :/
async function main() {
//#region Events
// Listen new workers // Listen new workers
cluster.on('fork', worker => { cluster.on('fork', worker => {
clusterLogger.debug(`Process forked: [${worker.id}]`); clusterLogger.debug(`Process forked: [${worker.id}]`);
@ -64,17 +67,14 @@ process.on('uncaughtException', err => {
process.on('exit', code => { process.on('exit', code => {
logger.info(`The process is going to exit with code ${code}`); logger.info(`The process is going to exit with code ${code}`);
}); });
//#endregion //#endregion
if (cluster.isPrimary || envOption.disableClustering) { if (cluster.isPrimary || envOption.disableClustering) {
await masterMain(); await masterMain();
if (cluster.isPrimary) { if (cluster.isPrimary) {
ev.mount(); ev.mount();
} }
} }
if (cluster.isWorker || envOption.disableClustering) { if (cluster.isWorker || envOption.disableClustering) {
await workerMain(); await workerMain();
} }
@ -84,3 +84,6 @@ if (cluster.isWorker || envOption.disableClustering) {
if (process.send) { if (process.send) {
process.send('ok'); process.send('ok');
} }
}
main();