core: 支持--busDetail启动选项,对.once.提供更好的debug支持

This commit is contained in:
undefined committed 2020-10-28 23:19:31 +08:00
1 parent ec2b95c91a
commit 289b378e0b
1 file changed
+6 -2
+6 -2
View File
@@ -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]) {
const dispose = addListener(name, function _listener(...args: any[]) {
let dispose;
function _listener(...args: any[]) {
dispose();
return listener.apply(this, args);
});
}
_listener.toString = () => `// Once \n${listener.toString()}`;
dispose = addListener(name, _listener);
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);
const hooks = Array.from(_hooks[name] || []);
for (const callback of hooks) {
if (argv.busDetail) console.log(callback.toString());
await callback.apply(this, args);
}
}