Hyperlinkv0.8.0-beta.28

Stream

Stream.runIntoPubSubconsteffect/Stream.ts:11471
<A>(
  pubsub: PubSub.PubSub<A>,
  options?: { readonly shutdownOnEnd?: boolean | undefined } | undefined
): <E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, R>
<A, E, R>(
  self: Stream<A, E, R>,
  pubsub: PubSub.PubSub<A>,
  options?: { readonly shutdownOnEnd?: boolean | undefined } | undefined
): Effect.Effect<void, never, R>

Runs the stream, publishing elements into the provided PubSub.

Details

shutdownOnEnd controls whether the PubSub is shut down when the stream ends. It only shuts down when set to true.

Example (Running a stream into a PubSub)

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

const program = Effect.scoped(Effect.gen(function* () {
  const pubsub = yield* PubSub.unbounded<number>()
  const subscription = yield* PubSub.subscribe(pubsub)

  yield* Stream.runIntoPubSub(Stream.fromIterable([1, 2]), pubsub)

  const first = yield* PubSub.take(subscription)
  const second = yield* PubSub.take(subscription)

  yield* Console.log(first)
  yield* Console.log(second)
}))

Effect.runPromise(program)
//=> 1
//=> 2
destructors
Source effect/Stream.ts:1147121 lines
export const runIntoPubSub: {
  <A>(
    pubsub: PubSub.PubSub<A>,
    options?: {
      readonly shutdownOnEnd?: boolean | undefined
    } | undefined
  ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, R>
  <A, E, R>(
    self: Stream<A, E, R>,
    pubsub: PubSub.PubSub<A>,
    options?: {
      readonly shutdownOnEnd?: boolean | undefined
    } | undefined
  ): Effect.Effect<void, never, R>
} = dual((args) => isStream(args[0]), <A, E, R>(
  self: Stream<A, E, R>,
  pubsub: PubSub.PubSub<A>,
  options?: {
    readonly shutdownOnEnd?: boolean | undefined
  } | undefined
): Effect.Effect<void, E, R> => Channel.runIntoPubSubArray(self.channel, pubsub, options))