import { IBackoff, IExponentialBackoffOptions } from './backoff/Backoff'; import { DelegateBackoffFn } from './backoff/DelegateBackoff'; import { CancellationToken } from './CancellationToken'; import { ExecuteWrapper } from './common/Executor'; import { FailureReason, IDefaultPolicyContext, IPolicy } from './Policy'; /** * Context passed into the execute method of the builder. */ export interface IRetryContext extends IDefaultPolicyContext { /** * The retry attempt, starting at 1 for calls into backoffs. */ attempt: number; } /** * Context passed into backoff delegated. */ export interface IRetryBackoffContext extends IRetryContext { /** * The result of the last method call. Either a thrown error, or a value * that we determined should be retried upon. */ result: FailureReason; } export interface IRetryPolicyConfig { backoff?: IBackoff>; /** * Whether to unreference the internal timer. This means the policy will not * keep the Node.js even loop active. Defaults to `false`. */ unref?: boolean; } export declare class RetryPolicy implements IPolicy { private options; private readonly executor; private readonly onGiveUpEmitter; private readonly onRetryEmitter; /** * @inheritdoc */ readonly onSuccess: import("./common/Event").Event; /** * @inheritdoc */ readonly onFailure: import("./common/Event").Event; /** * Emitter that fires when we retry a call, before any backoff. * */ readonly onRetry: import("./common/Event").Event<({ error: Error; } & { delay: number; }) | ({ value: unknown; } & { delay: number; })>; /** * @deprecated use `onFailure` instead */ readonly onGiveUp: import("./common/Event").Event>; constructor(options: Readonly, executor: ExecuteWrapper); /** * Sets the number of retry attempts for the function. * @param count Retry attempts to make */ attempts(count: number): RetryPolicy; /** * Sets the delay between retries. Can be a single duration, of a list of * durations. If it's a list, it will also determine the number of backoffs. */ delay(amount: number | ReadonlyArray): RetryPolicy; /** * Sets the baackoff to use for retries. */ delegate(backoff: DelegateBackoffFn, S>): RetryPolicy; /** * Uses an exponential backoff for retries. */ exponential(options?: Partial>): RetryPolicy; /** * Sets the baackoff to use for retries. */ backoff(backoff: IBackoff>): RetryPolicy; /** * When retrying, a referenced timer is created. This means the Node.js event * loop is kept active while we're delaying a retried call. Calling this * method on the retry builder will unreference the timer, allowing the * process to exit even if a retry might still be pending. */ dangerouslyUnref(): RetryPolicy; /** * Executes the given function with retries. * @param fn Function to run * @returns a Promise that resolves or rejects with the function results. */ execute(fn: (context: IRetryContext) => PromiseLike | T, cancellationToken?: CancellationToken): Promise; private composeBackoff; private derivePolicy; }