core: bail: change to async

This commit is contained in:
undefined committed 2021-07-08 11:59:35 +08:00
1 parent 8c83a79bee
commit c184d94dae
2 files changed
+4 -3

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.29.20",
"version": "2.29.21",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+3 -2
View File
@@ -173,11 +173,12 @@ export async function serial<K extends keyof EventMap>(name: K, ...args: Paramet
}
}
export function bail<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): ReturnType<EventMap[K]> {
export async function bail<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): ReturnType<EventMap[K]> {
if (argv.options.showBus && name !== 'message/log') logger.debug('bail: %s %o', name, args);
const hooks = Array.from(_hooks[name] || []);
for (const callback of hooks) {
const result = callback.apply(this, args);
let result = callback.apply(this, args);
if (result instanceof Promise) result = await result;
if (isBailed(result)) return result;
}
return null;