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

Function raceAll

packages/effect/src/internal/stream.ts:5072–5104  ·  view source on GitHub ↗
(
  ...streams: S
)

Source from the content-addressed store, hash-verified

5070
5071/** @internal */
5072export const raceAll = <S extends ReadonlyArray<Stream.Stream<any, any, any>>>(
5073 ...streams: S
5074): Stream.Stream<
5075 Stream.Stream.Success<S[number]>,
5076 Stream.Stream.Error<S[number]>,
5077 Stream.Stream.Context<S[number]>
5078> =>
5079 Deferred.make<void>().pipe(
5080 Effect.map((halt) => {
5081 let winner: number | null = null
5082 return mergeAll(
5083 streams.map((stream, index) =>
5084 stream.pipe(
5085 takeWhile(() => {
5086 if (winner === null) {
5087 winner = index
5088 Deferred.unsafeDone(halt, Exit.void)
5089 return true
5090 }
5091 return winner === index
5092 }),
5093 interruptWhen(
5094 Deferred.await(halt).pipe(
5095 Effect.flatMap(() => winner === index ? Effect.never : Effect.void)
5096 )
5097 )
5098 )
5099 ),
5100 { concurrency: streams.length }
5101 )
5102 }),
5103 unwrap
5104 )
5105
5106/** @internal */
5107export const rechunk = dual<

Callers 1

stream.tsFile · 0.70

Calls 6

unsafeDoneMethod · 0.80
mergeAllFunction · 0.70
pipeMethod · 0.65
makeMethod · 0.65
mapMethod · 0.65
awaitMethod · 0.45

Tested by

no test coverage detected