Hyperlinkv0.8.0-beta.28

Stream

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

Converts a stream to a PubSub of Take values for concurrent consumption.

Details

Take values include the stream's end and failure signals.

Example (Converting to a PubSub of takes)

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

const program = Effect.gen(function* () {
  const pubsub = yield* Stream.fromArray([1, 2, 3]).pipe(
    Stream.toPubSubTake({ capacity: 8 })
  )
  const subscription = yield* PubSub.subscribe(pubsub)
  const take = yield* PubSub.take(subscription)

  if (Array.isArray(take)) {
    yield* Console.log(take)
  }
})
destructors
Source effect/Stream.ts:1159137 lines
export const toPubSubTake: {
  (
    options: {
      readonly capacity: "unbounded"
      readonly replay?: number | undefined
    } | {
      readonly capacity: number
      readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
      readonly replay?: number | undefined
    }
  ): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<PubSub.PubSub<Take.Take<A, E>>, never, R | Scope.Scope>
  <A, E, R>(
    self: Stream<A, E, R>,
    options: {
      readonly capacity: "unbounded"
      readonly replay?: number | undefined
    } | {
      readonly capacity: number
      readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
      readonly replay?: number | undefined
    }
  ): Effect.Effect<PubSub.PubSub<Take.Take<A, E>>, never, R | Scope.Scope>
} = dual(
  2,
  <A, E, R>(
    self: Stream<A, E, R>,
    options: {
      readonly capacity: "unbounded"
      readonly replay?: number | undefined
    } | {
      readonly capacity: number
      readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
      readonly replay?: number | undefined
    }
  ): Effect.Effect<PubSub.PubSub<Take.Take<A, E>>, never, R | Scope.Scope> =>
    Channel.toPubSubTake(self.channel, options)
)
Referenced by 1 symbols