Skip to content
1 min read · 108 words

Function: sleepWithJitter()

ts
function sleepWithJitter(ms: number, signal?: AbortSignal): Promise<void>;

Defined in: lib/utils/retry.ts:47

Abort-aware jittered sleep used for retry backoff.

Parameters

ParameterTypeDescription
msnumberBase delay in ms; jittered by ±10%.
signal?AbortSignalOptional abort signal that short-circuits the sleep.

Returns

Promise<void>

Remarks

Resolves (never rejects) the instant signal aborts, so an aborted caller does not stay parked in a backoff delay — the caller's retry loop re-checks abort state immediately after and bails. The timer and the abort listener are both torn down on whichever fires first, so nothing leaks.