UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

64 lines 2.1 kB
/** * The context passed to a {@link RetryPolicy} callback. * @since 0.12.0 */ import * as dntShim from "../_dnt.shims.js"; export interface RetryContext { /** * The elapsed time since the first attempt. */ readonly elapsedTime: dntShim.Temporal.Duration; /** * The number of attempts so far. */ readonly attempts: number; } /** * A policy that determines the delay before the next retry. * @param context The retry context. * @returns The delay before the next retry, or `null` to stop retrying. * It must not negative. * @since 0.12.0 */ export type RetryPolicy = (context: RetryContext) => dntShim.Temporal.Duration | null; /** * Options for {@link createExponentialBackoffPolicy} function. * @since 0.12.0 */ export interface CreateExponentialBackoffPolicyOptions { /** * The initial delay before the first retry. Defaults to 1 second. */ readonly initialDelay?: dntShim.Temporal.DurationLike; /** * The maximum delay between retries. Defaults to 12 hours. */ readonly maxDelay?: dntShim.Temporal.DurationLike; /** * The maximum number of attempts before giving up. * Defaults to 10. */ readonly maxAttempts?: number; /** * The factor to multiply the previous delay by for each retry. * Defaults to 2. */ readonly factor?: number; /** * Whether to add jitter to the delay to avoid synchronization. * Turned on by default. */ readonly jitter?: boolean; } /** * Creates an exponential backoff retry policy. The delay between retries * starts at the `initialDelay` and is multiplied by the `factor` for each * subsequent retry, up to the `maxDelay`. The policy will give up after * `maxAttempts` attempts. The actual delay is randomized to avoid * synchronization (jitter). * @param options The options for the policy. * @returns The retry policy. * @since 0.12.0 */ export declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy; //# sourceMappingURL=retry.d.ts.map