UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

61 lines (60 loc) 1.8 kB
/** * @module BackoffPolicy */ import { type BackoffPolicy, type DynamicBackoffPolicy } from "../../../backoff-policies/contracts/_module.js"; import { type ITimeSpan } from "../../../time-span/contracts/_module.js"; /** * Configuration for the constant backoff policy. * Each retry waits for the same fixed `delay`, optionally randomised by a jitter * factor to spread out thundering-herd retries across multiple clients. * * IMPORT_PATH: `"@daiso-tech/core/backoff-policies"` * @group Implementations * @group Implementations */ export type ConstantBackoffSettings = { /** * Fixed wait duration applied between every retry attempt. * @default * ```ts * import { TimeSpan } from "@daiso-tech/core/time-span"; * * TimeSpan.fromSeconds(1) * ``` */ delay?: ITimeSpan; /** * Adds randomness to the delay to avoid thundering-herd effects. * Set to `null` to disable jitter. * @default 0.5 */ jitter?: number | null; /** * @internal * Should only be used for testing */ _mathRandom?: () => number; }; /** * @internal */ export declare function resolveConstantBackoffSettings(settings: ConstantBackoffSettings): Required<ConstantBackoffSettings>; /** * Constant backoff policy with jitter * * IMPORT_PATH: `"@daiso-tech/core/backoff-policies"` * @group Implementations */ export declare function constantBackoff(settings?: DynamicBackoffPolicy<ConstantBackoffSettings>): BackoffPolicy; /** * @internal */ export type SerializedConstantBackoffSettings = { delay?: number; jitter?: number | null; _mathRandom?: number; }; /** * @internal */ export declare function serializeConstantBackoffSettings(settings: ConstantBackoffSettings): Required<SerializedConstantBackoffSettings>;