From: Jérôme Benoit Date: Wed, 16 Oct 2024 15:50:36 +0000 (+0200) Subject: perf: speed up isAsyncFunction() helper X-Git-Tag: v4.4.0~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e155dc6f44e131201196c5537bff363d9d0b79bb;p=poolifier.git perf: speed up isAsyncFunction() helper Signed-off-by: Jérôme Benoit --- diff --git a/src/utils.ts b/src/utils.ts index 0e1266a1..3e22b8c1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -141,6 +141,8 @@ export const isKillBehavior = ( return value === killBehavior } +type AsyncFunctionType = (...args: A) => PromiseLike + /** * Detects whether the given value is an asynchronous function or not. * @param fn - Unknown value. @@ -149,8 +151,9 @@ export const isKillBehavior = ( */ export const isAsyncFunction = ( fn: unknown -): fn is (...args: unknown[]) => Promise => { - return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction' +): fn is AsyncFunctionType => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + return fn?.constructor === (async () => {}).constructor } /**