mini-effect
    Preparing search index...

    Function race

    • Runs all effects in parallel and resolves (or rejects) with whichever completes first.

      Type Parameters

      • const E extends Effect<any, any, any, any>[]

        A tuple of Effect types

      Parameters

      • values: E

        An array of effects to run in parallel

      Returns Effect<
          inferReturn<E[number]>,
          inferError<E[number]>,
          inferDependency<E[number]>,
          inferProvides<E[number]>,
      >

      An Effect that resolves or rejects with the first completion

      Behaves like Promise.race — all effects start concurrently and the returned effect settles with the outcome of the first effect to complete, whether it succeeds or fails. The remaining effects are aborted.

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

      const result = await run(race([
      fn(() => new Promise(r => setTimeout(() => r("slow"), 1000))),
      fn(() => new Promise(r => setTimeout(() => r("fast"), 100))),
      ]));
      // => "fast"