From e155dc6f44e131201196c5537bff363d9d0b79bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 16 Oct 2024 17:50:36 +0200 Subject: [PATCH] perf: speed up isAsyncFunction() helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 } /** -- 2.34.1