naystack - v1.9.9
    Preparing search index...

    Function withRetry

    • Runs an operation until it produces a result, backing off between tries.

      run signals failure by resolving null rather than throwing — the socials helpers log the API's message and resolve null, so a loop that only caught exceptions would never retry.

      Parameters

      • run: (attempt: number) => Promise<T | null>

        Receives the 1-based attempt number; resolve null to retry.

      • options: RetryOptions & {
            onRetry?: (attempt: number, attempts: number, delayMS: number) => void;
        } = {}

        RetryOptions, plus onRetry for logging before each delay.

      Returns Promise<T | null>

      The first non-null result, or null once every attempt is spent.

      import { withRetry } from "naystack/socials";

      const id = await withRetry(() => createContainer(token, params), {
      attempts: 3,
      onRetry: (attempt, attempts, delayMS) =>
      console.warn(`attempt ${attempt}/${attempts} failed — retrying in ${delayMS}ms`),
      });