mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 优化钩子逻辑
This commit is contained in:
1 parent
03dc8903e2
commit
f2f0212947
27 files changed
+205
-124
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user