Skip to content

Commit

Permalink
doc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jul 5, 2024
1 parent 51a44fc commit 45c3fad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
28 changes: 12 additions & 16 deletions .changeset/stream-race-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@

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"
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)
)
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))
Effect.runPromise(Stream.runDrain(stream));
// Output only from the first stream, the rest streams are interrupted
// 0
// 1
// 2
// 3
// 4
// 0
// 1
// 2
// 3
// 4
// 5
```
```
10 changes: 5 additions & 5 deletions packages/effect/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2696,17 +2696,17 @@ export const provideSomeLayer: {

/**
* 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.
* As soon as one of the upstream emits a first value, all the others are 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"
*
* const stream = Stream.raceAll(
* Stream.fromSchedule(Schedule.spaced('1 millis')),
* Stream.fromSchedule(Schedule.spaced('2 millis')),
* Stream.fromSchedule(Schedule.spaced('4 millis')),
* 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))
Expand All @@ -2718,7 +2718,7 @@ export const provideSomeLayer: {
* // 4
* // 5
* @since 3.5.0
* @category utils
* @category racing
*/
export const raceAll: <S extends ReadonlyArray<Stream<any, any, any>>>(
...streams: S
Expand Down

0 comments on commit 45c3fad

Please sign in to comment.