Skip to main content
Version: 0.96.0

Function: withRetry()

withRetry<T>(operation: () => Promise<T>, config: WithRetryConfig): Promise<T>

Defined in: utils.ts:538

Executes an async operation with retry logic and exponential backoff. Only retries on transient errors (as determined by shouldRetry from errors/utils).

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
operation() => Promise<T>Async function to execute
configWithRetryConfigRetry configuration

Returns

Promise<T>

Promise resolving to the operation result

Throws

The last error encountered after all retries are exhausted

Example

TypeScript
const result = await withRetry(
() => apiClient.getMessageById(id),
{
maxRetries: 3,
initialDelayMs: 1000,
backoffMultiplier: 2,
maxDelayMs: 30000,
respectRetryAfterHint: true,
}
)