mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: 支持--busDetail启动选项,对.once.提供更好的debug支持
This commit is contained in:
1 parent
ec2b95c91a
commit
289b378e0b
1 file changed
+6
-2
@@ -85,10 +85,13 @@ export function prependListener<K extends keyof EventMap>(name: K, listener: Eve
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function once<K extends keyof EventMap>(name: K, listener: EventMap[K]) {
|
export function once<K extends keyof EventMap>(name: K, listener: EventMap[K]) {
|
||||||
const dispose = addListener(name, function _listener(...args: any[]) {
|
let dispose;
|
||||||
|
function _listener(...args: any[]) {
|
||||||
dispose();
|
dispose();
|
||||||
return listener.apply(this, args);
|
return listener.apply(this, args);
|
||||||
});
|
}
|
||||||
|
_listener.toString = () => `// Once \n${listener.toString()}`;
|
||||||
|
dispose = addListener(name, _listener);
|
||||||
return dispose;
|
return dispose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +119,7 @@ export async function serial<K extends keyof EventMap>(name: K, ...args: Paramet
|
|||||||
if (argv.showBus) logger.debug('serial: %s %o', name, args);
|
if (argv.showBus) logger.debug('serial: %s %o', name, args);
|
||||||
const hooks = Array.from(_hooks[name] || []);
|
const hooks = Array.from(_hooks[name] || []);
|
||||||
for (const callback of hooks) {
|
for (const callback of hooks) {
|
||||||
|
if (argv.busDetail) console.log(callback.toString());
|
||||||
await callback.apply(this, args);
|
await callback.apply(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user