(all: Iterable<Effect.Effect<A, E, R>>)
| 2655 | export const raceAll: <Eff extends Effect.Effect<any, any, any>>( |
| 2656 | all: Iterable<Eff> |
| 2657 | ) => Effect.Effect<Effect.Effect.Success<Eff>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> = < |
| 2658 | A, |
| 2659 | E, |
| 2660 | R |
| 2661 | >(all: Iterable<Effect.Effect<A, E, R>>): Effect.Effect<A, E, R> => |
| 2662 | core.withFiberRuntime((state, status) => |
| 2663 | core.async<A, E, R>((resume) => { |
| 2664 | const fibers = new Set<FiberRuntime<A, E>>() |
| 2665 | let winner: FiberRuntime<A, E> | undefined |
| 2666 | let failures: Cause.Cause<E> = internalCause.empty |
| 2667 | const interruptAll = () => { |
| 2668 | for (const fiber of fibers) { |
| 2669 | fiber.unsafeInterruptAsFork(state.id()) |
| 2670 | } |
| 2671 | } |
| 2672 | let latch = false |
| 2673 | let empty = true |
| 2674 | for (const self of all) { |
| 2675 | empty = false |
| 2676 | const fiber = unsafeFork( |
| 2677 | core.interruptible(self), |
| 2678 | state, |
| 2679 | status.runtimeFlags |
| 2680 | ) |
| 2681 | fibers.add(fiber) |
| 2682 | fiber.addObserver((exit) => { |
| 2683 | fibers.delete(fiber) |
| 2684 | if (!winner) { |
| 2685 | if (exit._tag === "Success") { |
| 2686 | latch = true |
| 2687 | winner = fiber |
| 2688 | failures = internalCause.empty |
| 2689 | interruptAll() |
| 2690 | } else { |
| 2691 | failures = internalCause.parallel(exit.cause, failures) |
| 2692 | } |
| 2693 | } |
| 2694 | if (latch && fibers.size === 0) { |
| 2695 | resume( |
| 2696 | winner ? core.zipRight(internalFiber.inheritAll(winner), winner.unsafePoll()!) : core.failCause(failures) |
| 2697 | ) |
| 2698 | } |
| 2699 | }) |
| 2700 | if (winner) break |
| 2701 | } |
| 2702 | if (empty) { |
| 2703 | return resume(core.dieSync(() => new core.IllegalArgumentException(`Received an empty collection of effects`))) |
| 2704 | } |
| 2705 | latch = true |
| 2706 | return internalFiber.interruptAllAs(fibers, state.id()) |
| 2707 | }) |
| 2708 | ) |
| 2709 | |
| 2710 | /* @internal */ |
| 2711 | export const reduceEffect = dual< |
nothing calls this directly
no test coverage detected
searching dependent graphs…