footprintjs - v11.2.0
    Preparing search index...

    Function statedWaitFirst

    • A RetryPolicy.backoffMs function that honours a wait the outside system stated: when readStatedWaitMs(error) answers a finite number >= 0, that is the wait; otherwise inner (a backoff function, or a fixed number of milliseconds) decides. A reader that throws or answers anything else states nothing — a malformed Retry-After falls back to the schedule rather than to a wrong wait. The runner still caps the stated wait at maxBackoffMs and stops the series when it would outlast the run's deadline.

      The outside system chooses this wait, and a broken or hostile one can ask for an hour: whenever the wait comes from the server, declare the policy's maxBackoffMs (or run under a deadline).

      Parameters

      • readStatedWaitMs: StatedWaitReader
      • inner: NonNullable<number | ((attempt: number, error: unknown) => number) | undefined>

      Returns BackoffFunction

      const retryAfterMs = (error: unknown) => (error as { retryAfterMs?: number }).retryAfterMs;
      .retry({ attempts: 3, backoffMs: statedWaitFirst(retryAfterMs, exponentialBackoff({ baseDelayMs: 100 })), maxBackoffMs: 10_000 })