Executes an async function with backoff retry logic. If the function fails, it will be retried with increasing delays between attempts.

The last error encountered if all attempts fail

// With default parameters (3 attempts, 150ms base):
// 1st try: immediate
// 1st retry: 300ms delay (2^1 * 150)
// 2nd retry: 600ms delay (2^2 * 150)
// 3rd retry: 1200ms delay (2^3 * 150)
  • Type Parameters

    • T

    Parameters

    • fn: () => Promise<T>

      The async function to execute

    • attempts: number = 3

      Maximum number of retry attempts (default: 3)

    • backoffMs: number = 150

      Base delay in milliseconds for exponential backoff (default: 150)

    • backoffType: "exponential" | "linear" = 'exponential'

      The type of backoff to use (default: 'exponential')

    Returns Promise<T>

    Promise resolving to the function's result