Skip to content

Commit

Permalink
refactor(Stream/raceAll): improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dilame authored and gcanti committed Jul 4, 2024
1 parent 0efb065 commit 007f9f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 24 additions & 1 deletion .changeset/stream-race-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,27 @@
"effect": minor
---

feat(Stream): raceAll
feat(Stream): implement "raceAll" operator, which returns a stream that mirrors the first source stream to emit an item.


```ts
import { Stream, Schedule, Console, Effect } from "effect"

const stream = Stream.raceAll(
Stream.fromSchedule(Schedule.spaced('1 millis')),
Stream.fromSchedule(Schedule.spaced('2 millis')),
Stream.fromSchedule(Schedule.spaced('4 millis'))
).pipe(
Stream.take(6),
Stream.tap(Console.log)
)

Effect.runPromise(Stream.runDrain(stream))
// Output only from the first stream, the rest streams are interrupted
// 0
// 1
// 2
// 3
// 4
// 5
```
6 changes: 5 additions & 1 deletion packages/effect/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,11 @@ export const provideSomeLayer: {
} = internal.provideSomeLayer

/**
* Returns a stream that mirrors the first source stream to emit an item.
* Returns a stream that mirrors the first upstream to emit an item.
* As soon as one of the upstream emits a first value, all the others are being interrupted.
* The resulting stream will forward all items from the "winning" source stream.
* Any upstream failures will cause the returned stream to fail.
*
* @example
* import { Stream, Schedule, Console, Effect } from "effect"
*
Expand Down

0 comments on commit 007f9f6

Please sign in to comment.