Logos DX
    Preparing search index...

    Function retry

    • Retries a function until it succeeds or the number of retries is reached.

      Type Parameters

      Parameters

      Returns Promise<ReturnType<T>>

      const fetchData = retry(
      async () => {
      const response = await fetch('https://api.example.com/data');
      return response.json();
      },
      {
      retries: 3,
      delay: 1000,
      backoff: 2,
      shouldRetry: (error) => error.message.includes('500')
      }
      );

      const data = await fetchData();