Tweakr
    Preparing search index...

    Function retryAsync

    • Retry an async function until it succeeds or max attempts reached.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        Async function to retry.

      • attempts: number = 3

        Maximum retry attempts.

      Returns Promise<T>

      Result of successful function.

      const fn = async () => { if(Math.random()<0.5) throw new Error(); return 'ok'; };
      await retryAsync(fn, 3);

      1.2.0