Skip to main content

Function: retryWithAbort()

retryWithAbort<T>(operation: () => Promise<T>, options: RetryWithAbortOptions): Promise<T>

Defined in: shared/utils/abortUtils.ts:309

Retries an async operation with capped exponential backoff and abort handling.

Type Parametersโ€‹

Tโ€‹

T

Resolved value produced by the operation.

Parametersโ€‹

operationโ€‹

() => Promise<T>

Async function to invoke on each retry attempt.

optionsโ€‹

RetryWithAbortOptions = {}

Retry behavior tuning configuration.

Returnsโ€‹

Promise<T>

Promise that resolves with the operation result.

Remarksโ€‹

The retry loop waits after failed attempts using sleep. If the operation succeeds, the resolved value bypasses any remaining retries. As soon as the provided signal aborts, the function stops retrying and rejects.

Exampleโ€‹

const controller = new AbortController();

const result = await retryWithAbort(
async () => {
const response = await fetch(url);
if (!response.ok) throw new https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error("Request failed");
return response.json();
},
{
maxRetries: 3,
initialDelay: 1_000,
signal: controller.signal,
}
);

Throwsโ€‹

The last captured error when retries are exhausted.

Throwsโ€‹

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error When the supplied signal aborts before completion.