Wrap entry into async function
This commit is contained in:
parent
3d15f89638
commit
447399eb07
1 changed files with 49 additions and 46 deletions
|
@ -27,8 +27,11 @@ const logger = new Logger('core', 'cyan');
|
|||
const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
|
||||
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
|
||||
cluster.on('fork', worker => {
|
||||
clusterLogger.debug(`Process forked: [${worker.id}]`);
|
||||
|
@ -64,17 +67,14 @@ process.on('uncaughtException', err => {
|
|||
process.on('exit', code => {
|
||||
logger.info(`The process is going to exit with code ${code}`);
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
||||
if (cluster.isPrimary || envOption.disableClustering) {
|
||||
await masterMain();
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
ev.mount();
|
||||
}
|
||||
}
|
||||
|
||||
if (cluster.isWorker || envOption.disableClustering) {
|
||||
await workerMain();
|
||||
}
|
||||
|
@ -84,3 +84,6 @@ if (cluster.isWorker || envOption.disableClustering) {
|
|||
if (process.send) {
|
||||
process.send('ok');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Reference in a new issue