advanced-retry
Version:
A retry library with advanced features
33 lines (32 loc) • 1.48 kB
TypeScript
import { ErrorResolverBase, RetryContext } from '../retry';
import { CanHandleErrorFunction, ErrorFilter } from '../filter/base';
/**
* @description Delayed retry policy is used to configure the delay between retries and the maximum number of retries
* @property maxRetries - Maximum number of retries
* @property initialDelayMs - Initial delay in milliseconds
* @property maxDelayMs - Maximum delay in milliseconds
* @property backoffMultiplier - Backoff multiplier, the delay is calculated as initialDelayMs * (attempt + 1) * backoffMultiplier
* @property customDelay - Custom delay function. Customize the delay to your liking
*/
export interface DelayPolicy<X = any | undefined> {
maxRetries: number;
initialDelayMs?: number;
maxDelayMs?: number;
backoffMultiplier?: number;
customDelay?: ({ attempt, error, context, configuration, }: {
attempt: number;
error: unknown;
context: RetryContext<X>;
configuration: DelayPolicy;
}) => number;
}
/**
* @description Delayed retry error resolver is used to handle the error and retry the operation after a delay
* @param configuration - Delayed retry policy
* @param canHandleError - Can handle error function
* @returns Error resolver
*/
export declare const delayErrorResolver: <X = any>({ configuration, canHandleError, }: {
configuration: DelayPolicy;
canHandleError?: CanHandleErrorFunction<X> | ErrorFilter<X>;
}) => ErrorResolverBase<RetryContext<X>, X>;