Hyperlinkv0.8.0-beta.28

Effect

Effect.raceAllconsteffect/Effect.ts:4748
<Eff extends Effect<any, any, any>>(
  all: Iterable<Eff>,
  options?: {
    readonly onWinner?: (options: {
      readonly fiber: Fiber<any, any>
      readonly index: number
      readonly parentFiber: Fiber<any, any>
    }) => void
  }
): Effect<Success<Eff>, Error<Eff>, Services<Eff>>

Runs multiple effects concurrently and returns the first successful result.

When to use

Use when early failures should be ignored until a success occurs or all effects fail.

Details

Early failures do not finish the race; raceAll keeps waiting until one effect succeeds or every effect has failed. When one effect succeeds, the remaining effects are interrupted. If every effect fails, the returned effect fails with a cause containing the collected failure reasons.

Example (Racing many effects)

import { Duration, Effect } from "effect"

// Multiple effects with different delays
const effect1 = Effect.delay(Effect.succeed("Fast"), Duration.millis(100))
const effect2 = Effect.delay(Effect.succeed("Slow"), Duration.millis(500))
const effect3 = Effect.delay(Effect.succeed("Very Slow"), Duration.millis(1000))

// Race all effects - the first to succeed wins
const raced = Effect.raceAll([effect1, effect2, effect3])

// Result: "Fast" (after ~100ms)
racingrace
Source effect/Effect.ts:474810 lines
export const raceAll: <Eff extends Effect<any, any, any>>(
  all: Iterable<Eff>,
  options?: {
    readonly onWinner?: (options: {
      readonly fiber: Fiber<any, any>
      readonly index: number
      readonly parentFiber: Fiber<any, any>
    }) => void
  }
) => Effect<Success<Eff>, Error<Eff>, Services<Eff>> = internal.raceAll
Referenced by 1 symbols