UNPKG

@ts-common/azure-js-dev-tools

Version:

Developer dependencies for TypeScript related projects

62 lines 2.12 kB
/** * An error that can be wrapped around another error that indicates that the action should not be * retried. */ export declare class DontRetryError extends Error { readonly innerError: Error; constructor(innerError: Error); } /** * A control object that is passed to a retriable action. */ export interface RetryControl { /** * The attempt number. */ readonly attempt: number; /** * The maximum number of attempts that will be made. */ readonly maxAttempts: number; /** * Whether or not the retry function should attempt to run the action again when an error is * encountered.. */ shouldRetry?: boolean; /** * The errors that have occurred on previous attempts. */ readonly errors: Error[]; } export declare type RetryFunction<T> = (control: RetryControl) => (T | Promise<T>); export declare type ShouldRetryFunction<T> = (error: Error | undefined, result: T | undefined, control: RetryControl) => (boolean | Promise<boolean>); export declare type BetweenAttemptsFunction<T> = (error: Error | undefined, result: T | undefined, control: RetryControl) => (unknown | Promise<unknown>); /** * Options that can be passed to the retry() function. */ export interface RetryOptions<T> { /** * The retriable action. */ action: RetryFunction<T>; /** * The maximum number of attempts. Defaults to 3. */ maxAttempts?: number; /** * Whether or not to retry when the provided error was thrown. */ shouldRetry?: ShouldRetryFunction<T>; /** * A function that should be run between attempts. */ betweenAttempts?: BetweenAttemptsFunction<T>; } /** * Attempt to run the provided action. If the action throws an error, then it will be retried up to * 2 more times. If the action still throws an error on the 3rd attempt (2nd retry), then the error * will be thrown to the caller of this function. * @param action The action that will be run. */ export declare function retry<T>(action: RetryFunction<T> | RetryOptions<T>): Promise<T>; //# sourceMappingURL=retry.d.ts.map