Hyperlinkv0.8.0-beta.28

Stream

Stream.broadcastconsteffect/Stream.ts:8899
(
  options:
    | {
        readonly capacity: "unbounded"
        readonly replay?: number | undefined
      }
    | {
        readonly capacity: number
        readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
        readonly replay?: number | undefined
      }
): <A, E, R>(
  self: Stream<A, E, R>
) => Effect.Effect<Stream<A, E>, never, Scope.Scope | R>
<A, E, R>(
  self: Stream<A, E, R>,
  options:
    | {
        readonly capacity: "unbounded"
        readonly replay?: number | undefined
      }
    | {
        readonly capacity: number
        readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
        readonly replay?: number | undefined
      }
): Effect.Effect<Stream<A, E>, never, Scope.Scope | R>

Creates a PubSub-backed stream that multicasts the source to all subscribers.

Details

The returned stream is scoped and uses the provided PubSub capacity and replay settings.

Example (Broadcasting a stream)

import { Console, Effect, Stream } from "effect"

const program = Effect.scoped(
  Effect.gen(function* () {
    const broadcasted = yield* Stream.broadcast(Stream.fromArray([1, 2, 3]), {
      capacity: 8,
      replay: 3
    })

    const [left, right] = yield* Effect.all([
      Stream.runCollect(broadcasted),
      Stream.runCollect(broadcasted)
    ], { concurrency: "unbounded" })

    yield* Console.log([left, right])
  })
)

Effect.runPromise(program)
// Output: [[1, 2, 3], [1, 2, 3]]
Broadcast
Source effect/Stream.ts:889933 lines
export const broadcast: {
  (
    options: {
      readonly capacity: "unbounded"
      readonly replay?: number | undefined
    } | {
      readonly capacity: number
      readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
      readonly replay?: number | undefined
    }
  ): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Stream<A, E>, never, Scope.Scope | R>
  <A, E, R>(
    self: Stream<A, E, R>,
    options: {
      readonly capacity: "unbounded"
      readonly replay?: number | undefined
    } | {
      readonly capacity: number
      readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
      readonly replay?: number | undefined
    }
  ): Effect.Effect<Stream<A, E>, never, Scope.Scope | R>
} = dual(2, <A, E, R>(
  self: Stream<A, E, R>,
  options: {
    readonly capacity: "unbounded"
    readonly replay?: number | undefined
  } | {
    readonly capacity: number
    readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
    readonly replay?: number | undefined
  }
): Effect.Effect<Stream<A, E>, never, Scope.Scope | R> => Effect.map(toPubSubTake(self, options), fromPubSubTake))
Referenced by 1 symbols