mini-effect
    Preparing search index...

    Function retry

    • Retries a failing Effect up to a specified number of times, or indefinitely until it succeeds.

      Type Parameters

      • R extends number | "forever"

        The retry count type: number or "forever"

      • T

        The success value type of the effect

      • C

        The error type of the effect

      • D

        Dependencies required by the effect

      • P

        Dependencies provided by the effect

      Parameters

      • times: R

        The maximum number of retries, or "forever" for unlimited retries

      • effect: Effect<T, C, D, P>

        The Effect to retry on failure

      Returns Effect<T, R extends "forever" ? never : C, D, P>

      A new Effect that retries the original effect on failure. When times is "forever", the error type is never.

      When times is a number, the effect is retried up to that many times after the initial attempt. If it still fails after all retries, the last error propagates. When times is "forever", the effect is retried indefinitely and the error type narrows to never — the effect will eventually succeed or run forever.

      Internally, retry uses catchSome and pipe to re-execute the effect on each failure.

      import { retry, fn, run } from "mini-effect";

      // Retry up to 3 times before failing
      const resilient = retry(
      3,
      fn(() => fetchUnreliableData()),
      );

      // Retry forever until success
      const persistent = retry(
      "forever",
      fn(() => pollUntilReady()),
      );