diff --git a/index.ts b/index.ts index 5616684..1844501 100644 --- a/index.ts +++ b/index.ts @@ -58,11 +58,19 @@ export async function pSignal( } export function isAbortError(value: unknown): value is Error { + // checking for "TimeoutError" as well because of AbortSignal.timeout(time): + // https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout + if (typeof DOMException === 'undefined') { - return value instanceof Error && value.name === 'AbortError' + return ( + value instanceof Error && (value.name === 'AbortError' || value.name === 'TimeoutError') + ) } - return value instanceof DOMException && value.name === 'AbortError' + return ( + value instanceof DOMException && + (value.name === 'AbortError' || value.name === 'TimeoutError') + ) } function createAbortError(): Error {