From 22df69fdecf299c8be6acaa25f086249ea9a0085 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 Aug 2022 15:29:00 +0200 Subject: Add job queue hooks --- shared/core-utils/plugins/hooks.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'shared/core-utils') diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 92cb5ad68..3784969b5 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts @@ -8,15 +8,24 @@ function getHookType (hookName: string) { return HookType.STATIC } -async function internalRunHook (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { +async function internalRunHook (options: { + handler: Function + hookType: HookType + result: T + params: any + onError: (err: Error) => void +}) { + const { handler, hookType, result, params, onError } = options + try { if (hookType === HookType.FILTER) { const p = handler(result, params) - if (isPromise(p)) result = await p - else result = p + const newResult = isPromise(p) + ? await p + : p - return result + return newResult } // Action/static hooks do not have result value -- cgit v1.2.3