ts-retry
Version:
A little retry tool to execute a function until the function is successful. Can also bind a timeout to a function. This lib is usable in typescript, in javascript, in node, in SPA tools (rest, Vue, Svelte...) and browser (available in ESM and common js fo
23 lines (22 loc) • 1.06 kB
TypeScript
export type UNTIL<RETURN_TYPE> = (result: RETURN_TYPE) => boolean;
export interface DelayParameters<RETURN_TYPE> {
currentTry: number;
maxTry: number;
lastDelay?: number;
lastResult?: RETURN_TYPE;
lastError?: Error;
}
export type DELAY<RETURN_TYPE> = (parameter: DelayParameters<RETURN_TYPE>) => number;
export interface RetryOptions<RETURN_TYPE = any> {
maxTry?: number;
delay?: number | DELAY<RETURN_TYPE>;
until?: UNTIL<RETURN_TYPE> | null;
onError?: (err: Error, currentTry: number) => boolean | undefined;
onMaxRetryFunc?: (err: Error, currentTry: number) => void;
onSuccessFunc?: (result: RETURN_TYPE, currentTry: number) => void;
}
export declare const defaultDelay = 250;
export declare const defaultMaxTry: number;
export declare let defaultRetryOptions: RetryOptions<any>;
export declare function setDefaultRetryOptions<RETURN_TYPE>(retryOptions: RetryOptions<RETURN_TYPE>): RetryOptions<RETURN_TYPE>;
export declare function getDefaultRetryOptions<RETURN_TYPE = any>(): Readonly<RetryOptions<RETURN_TYPE>>;