Hyperlinkv0.8.0-beta.28

Stream

Stream.fromPubSubconsteffect/Stream.ts:1328
<A>(pubsub: PubSub.PubSub<A>): Stream<A>

Creates a stream from a subscription to a PubSub.

Example (Creating a stream from a subscription to a PubSub)

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

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

  const fiber = yield* Stream.fromPubSub(pubsub).pipe(
    Stream.take(3),
    Stream.runCollect,
    Effect.forkChild
  )

  yield* PubSub.publish(pubsub, 1)
  yield* PubSub.publish(pubsub, 2)
  yield* PubSub.publish(pubsub, 3)

  const values = yield* Fiber.join(fiber)
  yield* Console.log(values)
})

Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
constructors
Source effect/Stream.ts:13281 lines
export const fromPubSub = <A>(pubsub: PubSub.PubSub<A>): Stream<A> => fromChannel(Channel.fromPubSubArray(pubsub))
Referenced by 1 symbols