• Retry a function with exponential backoff.

    Type Parameters

    • T

      Return type of the function.

    Parameters

    • fn: (() => Promise<T>)

      Async function to retry.

        • (): Promise<T>
        • Returns Promise<T>

    • maxAttempts: number = 3

      Maximum number of attempts (default 3).

    • baseDelayMs: number = 500

      Base delay between retries in ms (default 500). Doubles each attempt.

    Returns Promise<T>

    The result of the first successful invocation.

    The last error if all attempts fail.

    1.0.0

    const data = await retry(() => fetch('/api'), 5, 1000);