@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.
72 lines (71 loc) • 2.11 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 linear backoff policy.
* The wait time increases linearly with each retry attempt and is capped at
* `maxDelay`. An optional `jitter` factor randomises the delay
* to spread out concurrent retries.
*
* IMPORT_PATH: `"@daiso-tech/core/backoff-policies"`
* @group Implementations
*/
export type LinearBackoffSettings = {
/**
* 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 linearly from this base.
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromMilliseconds(500)
* ```
*/
minDelay?: 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 resolveLinearBackoffSettings(settings: LinearBackoffSettings): Required<LinearBackoffSettings>;
/**
* Linear backoff policy with jitter
*
* IMPORT_PATH: `"@daiso-tech/core/backoff-policies"`
* @group Implementations
*/
export declare function linearBackoff(settings?: DynamicBackoffPolicy<LinearBackoffSettings>): BackoffPolicy;
/**
* @internal
*/
export type SerializedLinearBackoffSettings = {
maxDelay?: number;
minDelay?: number;
jitter?: number | null;
_mathRandom?: number;
};
/**
* @internal
*/
export declare function serializeLinearBackoffSettings(settings: LinearBackoffSettings): Required<SerializedLinearBackoffSettings>;