Hyperlinkv0.8.0-beta.28

PubSub

PubSub.unboundedconsteffect/PubSub.ts:472
<A>(options?: { readonly replay?: number | undefined }): Effect.Effect<
  PubSub<A>
>

Creates an unbounded PubSub.

Example (Creating an unbounded PubSub)

import { Effect, PubSub } from "effect"

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

  // With replay buffer for late subscribers
  const pubsubWithReplay = yield* PubSub.unbounded<string>({
    replay: 10
  })

  yield* Effect.scoped(Effect.gen(function*() {
    const subscription = yield* PubSub.subscribe(pubsub)

    // Can publish unlimited messages
    for (let i = 0; i < 3; i++) {
      yield* PubSub.publish(pubsub, `message-${i}`)
    }

    const message = yield* PubSub.take(subscription)
    console.log("First message:", message) // "message-0"
  }))
})
constructors
Source effect/PubSub.ts:4727 lines
export const unbounded = <A>(options?: {
  readonly replay?: number | undefined
}): Effect.Effect<PubSub<A>> =>
  make({
    atomicPubSub: () => makeAtomicUnbounded(options),
    strategy: () => new DroppingStrategy()
  })
Referenced by 1 symbols