Hiyve Components - v1.0.0
    Preparing search index...
    • Execute an async function with exponential backoff retry.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        Async function to execute

      • options: RetryOptions = {}

        Retry options

      Returns Promise<T>

      Promise resolving to the function's result

      This utility handles transient failures by automatically retrying the operation with increasing delays between attempts.

      Basic usage:

      const result = await withRetry(
      () => fetchData('/api/data'),
      { maxRetries: 3 }
      );

      With custom retry logic:

      const result = await withRetry(
      () => uploadFile(file),
      {
      maxRetries: 5,
      initialDelay: 500,
      isRetryable: (error) => {
      // Only retry network errors
      return error instanceof TypeError && error.message.includes('fetch');
      },
      onRetry: (attempt, error, delay) => {
      console.log(`Retry ${attempt} after ${delay}ms:`, error);
      },
      }
      );

      The last error if all retries are exhausted