Vize

retry-delay

Calculate a bounded exponential-backoff delay for a one-based retry.

Package @vizejs/composable/retry-delay
Own the source vize lib pull composable:retry-delay
Runtime exports calculateRetryDelay
Gzip budget 1536 B

Usage

import { calculateRetryDelay } from "@vizejs/composable/retry-delay";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
calculateRetryDelay timing experimental safe not-applicable none web, server, worker, native, desktop, terminal — —

API

calculateRetryDelay

Calculate a bounded exponential-backoff delay for a one-based retry. The first retry is retryAttempt = 1. The result is always an integer from zero through 2_147_483_647, making it safe to pass to common host timer APIs without implementation-specific clamping. The calculation is pure unless jitter requires the supplied entropy source, and it performs no work when the module is imported. Jitter samples uniformly from the inclusive integer range ceil(cappedDelay * (1 - jitterRatio))...cappedDelay. Capping occurs before jitter, so neither floating-point overflow nor entropy can exceed the configured maximum.

function calculateRetryDelay(retryAttempt: number, options: RetryDelayOptions = {}): number

Types

RetryDelayOptions

Options for calculateRetryDelay.

Member Type Description
initialDelayMs? number Delay before the first retry, in milliseconds.
multiplier? number Exponential multiplier applied for each subsequent retry. Values may be fractional but must be finite and at least one. The calculated delay is rounded up so a retry never starts earlier than the requested backoff.
maximumDelayMs? number Inclusive ceiling for the calculated delay, in milliseconds. The ceiling may be lower than RetryDelayOptions.initialDelayMs; in that case it also caps the first retry.
jitterRatio? number Fraction of the capped delay eligible for downward jitter. 0 is deterministic exponential backoff, 0.5 samples from the upper half of the range, and 1 applies full jitter from zero through the capped delay. Jitter never exceeds the unjittered delay.
random? () => number Entropy source returning a number in the half-open interval [0, 1). It is called exactly once when the selected jitter range contains more than one integer millisecond, and is otherwise not read.