MCPcopy
hub / github.com/Effect-TS/effect / raceAllFirst

Function raceAllFirst

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…