mini-effect
    Preparing search index...

    Function fn

    • Creates a lazy Effect from a thunk function.

      Type Parameters

      • R

        The success value type produced by the thunk

      • C = never

        The error type that may be thrown by the thunk (defaults to never)

      Parameters

      • thunk: Thunk<R>

        A function receiving an AbortSignal that returns R or Promise<R>

      Returns Effect<R, C, never, never>

      A lazy Effect that, when run, invokes the thunk

      The thunk receives an AbortSignal that is triggered when the effect is cancelled. The thunk may return a value synchronously or a Promise for asynchronous work. The effect is not executed until it is passed to run.

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

      const delay = fn(
      (signal) =>
      new Promise<void>((resolve, reject) => {
      const id = setTimeout(resolve, 1000);
      signal.addEventListener("abort", () => {
      clearTimeout(id);
      reject(signal.reason);
      });
      }),
      );

      await run(delay);