@peerbit/time
Advanced tools
Comparing version 2.0.7-2d408db to 2.0.7-2de0560
@@ -26,7 +26,12 @@ export class TimeoutError extends Error { | ||
let stop = false; | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
}; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
@@ -41,3 +46,8 @@ while (!stop && Number(new Date()) - startTime < timeout) { | ||
} | ||
throw createTimeoutError(options); | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
else { | ||
throw createTimeoutError(options); | ||
} | ||
}; | ||
@@ -50,7 +60,12 @@ export const waitForResolved = async (fn, options = { timeout: 10 * 1000, delayInterval: 50 }) => { | ||
let lastError; | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
}; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
@@ -73,4 +88,7 @@ while (!stop && Number(new Date()) - startTime < timeout) { | ||
} | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
throw lastError || createTimeoutError(options); | ||
}; | ||
//# sourceMappingURL=wait.js.map |
{ | ||
"name": "@peerbit/time", | ||
"version": "2.0.7-2d408db", | ||
"version": "2.0.7-2de0560", | ||
"description": "Utility functions for time", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -39,4 +39,6 @@ export class TimeoutError extends Error {} | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
@@ -46,2 +48,5 @@ }; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
@@ -58,3 +63,7 @@ // eslint-disable-next-line no-unmodified-loop-condition | ||
} | ||
throw createTimeoutError(options); | ||
if (aborted) { | ||
throw new AbortError(); | ||
} else { | ||
throw createTimeoutError(options); | ||
} | ||
}; | ||
@@ -78,4 +87,6 @@ | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
@@ -85,2 +96,5 @@ }; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
@@ -103,3 +117,7 @@ // eslint-disable-next-line no-unmodified-loop-condition | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
throw lastError || createTimeoutError(options); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21756
363