core: 优化钩子逻辑

This commit is contained in:
undefined committed 2020-09-06 11:31:49 +08:00
1 parent 03dc8903e2
commit f2f0212947
27 files changed
+205 -124

No files matched your search

+5 -4
View File
@@ -36,9 +36,7 @@ if (!global.Hydro) {
// @ts-ignore
error: {},
locales: {},
postInit: [],
};
global.onDestory = [];
global.addons = [];
}
@@ -47,9 +45,12 @@ if (argv.debug) {
console.log(argv);
}
// eslint-disable-next-line import/first
import * as bus from './service/bus';
async function terminate() {
try {
for (const task of global.onDestory) await task();
await bus.parallel('app/exit');
} catch (e) {
process.exit(1);
}
@@ -127,7 +128,7 @@ async function messageHandler(worker: cluster.Worker, msg: any) {
cluster.workers[i].send(msg);
}
} else {
global.Hydro.service.bus.publish(msg.eventName, msg.payload, false);
global.Hydro.service.bus.emit(msg.eventName, ...msg.payload);
}
} else if (msg.event === 'stat') {
global.Hydro.stat.reqCount += msg.count;