@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.
78 lines (77 loc) • 2.36 kB
TypeScript
/**
* @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 polynomial backoff policy.
* The wait time grows as `minDelay * attempt^degree`, clamped to `maxDelay`.
* An optional `jitter` factor randomises the delay to reduce retry collisions.
*
* IMPORT_PATH: `"@daiso-tech/core/backoff-policies"`
* @group Implementations
*/
export type PolynomialBackoffSettings = {
/**
* Upper bound on the computed delay. The wait time will never exceed this value.
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromSeconds(60)
* ```
*/
maxDelay?: ITimeSpan;
/**
* Starting delay for the first retry. Subsequent delays grow from this base.
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromMilliseconds(500)
* ```
*/
minDelay?: ITimeSpan;
/**
* The exponent of the polynomial used to calculate the delay: `minDelay * attempt^degree`.
* Higher values produce faster growth in wait times.
* @default 2
*/
degree?: number;
/**
* 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 resolvePolynomialBackoffSettings(settings: PolynomialBackoffSettings): Required<PolynomialBackoffSettings>;
/**
* Polynomial backoff policy with jitter
*
* IMPORT_PATH: `"@daiso-tech/core/backoff-policies"`
* @group Implementations
*/
export declare function polynomialBackoff(settings?: DynamicBackoffPolicy<PolynomialBackoffSettings>): BackoffPolicy;
/**
* @internal
*/
export type SerializedPolynomialBackoffSettings = {
maxDelay?: number;
minDelay?: number;
degree?: number;
jitter?: number | null;
_mathRandom?: number;
};
/**
* @internal
*/
export declare function serializePolynomialBackoffSettings(settings: PolynomialBackoffSettings): Required<SerializedPolynomialBackoffSettings>;