Skip to content

Commit

Permalink
refactor(Stream/raceAll): improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
dilame authored and tim-smart committed Jul 4, 2024
1 parent 9e4f134 commit ff58c53
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions packages/effect/src/internal/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4695,34 +4695,30 @@ export const raceAll = <S extends ReadonlyArray<Stream.Stream<any, any, any>>>(
> =>
Deferred.make<void>().pipe(
Effect.map((halt) => {
let winner: number | null = null;
let winner: number | null = null
return mergeAll(
streams.map((stream, index) =>
stream.pipe(
takeWhile(() => {
if (winner === index) {
return true;
} else if (winner === null) {
winner = index;
Deferred.unsafeDone(halt, Exit.void);
return true;
if (winner === null) {
winner = index
Deferred.unsafeDone(halt, Exit.void)
return true
}
return false;
return winner === index
}),
interruptWhen(
Deferred.await(halt).pipe(
Effect.flatMap(() =>
winner === index ? Effect.never : Effect.void,
),
),
),
),
Effect.flatMap(() => winner === index ? Effect.never : Effect.void)
)
)
)
),
{ concurrency: streams.length },
);
{ concurrency: streams.length }
)
}),
unwrap,
);
unwrap
)

/** @internal */
export const rechunk = dual<
Expand Down

0 comments on commit ff58c53

Please sign in to comment.