UNPKG

keep-trying

Version:

A function for creating retryable promises with configurable limit and backoff.

21 lines (20 loc) 622 B
import { JitterType } from './jitter'; import { BackoffType } from './backoff'; declare type PromiseFunction<T> = (...args: any[]) => Promise<T>; interface Options { baseTime?: number; maxAttempts?: number; maxTime?: number; backoffStrategy?: BackoffType; jitterStrategy?: JitterType; logger?(status: RetryStatus): any; } export interface RetryStatus { attempt: number; maxAttempts: number; nextAttemptIn?: number; state: 'retrying' | 'failed'; error?: Error; } declare const keepTrying: (fn: PromiseFunction<any>, options?: Options) => Promise<any>; export default keepTrying;