• Compute the backoff delay for a given (0-based) retry attempt.

    Without jitter the sequence is base, base*2, base*4, … capped at maxDelayMs (i.e. 1s, 2s, 4s, 8s, 16s, 30s for the defaults). With full jitter the delay is a random value in [0, cappedDelay] to avoid a thundering herd.

    Parameters

    • attempt: number
    • baseDelayMs: number = DEFAULT_BASE_DELAY_MS
    • maxDelayMs: number = DEFAULT_MAX_DELAY_MS
    • jitter: boolean = true

    Returns number