UNPKG

@bernierllc/retry-policy

Version:

Atomic retry policy utilities with exponential backoff and jitter

59 lines 1.81 kB
/** * Configuration options for retry policies */ export interface RetryPolicyOptions { /** Maximum number of retry attempts */ maxRetries: number; /** Initial delay in milliseconds */ initialDelayMs: number; /** Maximum delay in milliseconds */ maxDelayMs?: number; /** Exponential backoff factor */ backoffFactor?: number; /** Whether to apply jitter to delays */ jitter?: boolean; /** Function to determine if an error should trigger a retry */ shouldRetry?: (error: any) => boolean; /** Callback function called before each retry attempt */ onRetry?: (attempt: number, delay: number, error: any) => void; /** Callback function called when all retries are exhausted */ onFailure?: (error: any) => void; } /** * Result of a retry policy evaluation */ export interface RetryPolicyResult { /** Whether the operation should be retried */ shouldRetry: boolean; /** Delay in milliseconds before next retry */ delay: number; /** Current attempt number */ attempt: number; /** Whether this is the final attempt */ isFinalAttempt: boolean; } /** * Jitter configuration for retry delays */ export interface JitterConfig { /** Type of jitter to apply */ type: 'none' | 'full' | 'equal' | 'decorrelated'; /** Jitter factor (0-1) */ factor?: number; } /** * Backoff strategy configuration */ export interface BackoffConfig { /** Type of backoff strategy */ type: 'exponential' | 'linear' | 'constant'; /** Base delay in milliseconds */ baseDelay: number; /** Maximum delay in milliseconds */ maxDelay: number; /** Backoff factor for exponential strategies */ factor?: number; /** Jitter configuration */ jitter?: JitterConfig; } //# sourceMappingURL=types.d.ts.map