MCPcopy Create free account
hub / github.com/Effect-TS/effect / raceAllFirst

Function raceAllFirst

packages/effect/src/Micro.ts:1458–1482  ·  view source on GitHub ↗
(
  all: Iterable<Eff>
)

Source from the content-addressed store, hash-verified

1456 * @category sequencing
1457 */
1458export const raceAllFirst = <Eff extends Micro<any, any, any>>(
1459 all: Iterable<Eff>
1460): Micro<Micro.Success<Eff>, Micro.Error<Eff>, Micro.Context<Eff>> =>
1461 withMicroFiber((parent) =>
1462 async((resume) => {
1463 let done = false
1464 const fibers = new Set<MicroFiber<any, any>>()
1465 const onExit = (exit: MicroExit<any, any>) => {
1466 done = true
1467 resume(fibers.size === 0 ? exit : flatMap(fiberInterruptAll(fibers), () => exit))
1468 }
1469
1470 for (const effect of all) {
1471 if (done) break
1472 const fiber = unsafeFork(parent, interruptible(effect), true, true)
1473 fibers.add(fiber)
1474 fiber.addObserver((exit) => {
1475 fibers.delete(fiber)
1476 onExit(exit)
1477 })
1478 }
1479
1480 return fiberInterruptAll(fibers)
1481 })
1482 )
1483
1484/**
1485 * Returns an effect that races two effects, yielding the value of the first

Callers 1

Micro.tsFile · 0.85

Calls 7

asyncFunction · 0.85
fiberInterruptAllFunction · 0.85
unsafeForkFunction · 0.70
interruptibleFunction · 0.70
onExitFunction · 0.70
addMethod · 0.65
addObserverMethod · 0.65

Tested by

no test coverage detected