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 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();
|
||||||
|
|
Loading…
Reference in a new issue