UNPKG

retryable-operation

Version:

a simple package that allow executing retryable operation and providing retry options

44 lines 1.35 kB
import { Result } from "./result"; export interface RetryOptions<T = unknown, E = unknown> { fn: AttemptedFunction<T>; args?: any[]; reties?: number; factor?: number; shouldRetry?: (err: E, attempts: number) => boolean; executor?: Executor<T>; maxDelay?: number; minDelay?: number; } export declare type AttemptedFunction<T> = (...args: any[]) => T | Promise<T>; export declare type Executor<T> = (fn: AttemptedFunction<T>) => Promise<T>; export declare type OperationResult<T, E> = Result<T, E> & { readonly operationRef: RetryableOperation<T, E>; }; export declare class RetryableOperation<T = unknown, E = unknown> { private fn; private args; private _errors; private _attempts; private shouldRetry; private retries; private factor; private timeout; private maxDelay; private minDelay; private _executor?; constructor(_options: RetryOptions<T>); attempt(): Promise<OperationResult<T, E>>; setExecutor(executor: Executor<T>): this; setArgs(...args: any[]): this; set executor(executor: Executor<T>); get options(): { retries: number; factor: number; args: any[]; maxDelay: number; minDelay: number; }; get attempts(): number; get errors(): E[]; } //# sourceMappingURL=retryable-operation.d.ts.map