Hyperlinkv0.8.0-beta.28

TxPubSub

TxPubSub.unboundedconsteffect/TxPubSub.ts:228
<A = never>(): Effect.Effect<TxPubSub<A>>

Creates an unbounded TxPubSub with unlimited capacity. Messages are always accepted.

Example (Creating an unbounded pub/sub)

import { Effect, TxPubSub, TxQueue } from "effect"

const program = Effect.gen(function*() {
  const hub = yield* TxPubSub.unbounded<string>()

  yield* Effect.scoped(
    Effect.gen(function*() {
      const sub = yield* TxPubSub.subscribe(hub)
      yield* TxPubSub.publish(hub, "msg")
      const msg = yield* TxQueue.take(sub)
      console.log(msg) // "msg"
    })
  )
})
constructors
export const unbounded = <A = never>(): Effect.Effect<TxPubSub<A>> =>
  Effect.gen(function*() {
    const subscribersRef = yield* TxRef.make<Array<TxQueue.TxQueue<A>>>([])
    const shutdownRef = yield* TxRef.make(false)
    return makeTxPubSub(subscribersRef, shutdownRef, "unbounded", Number.POSITIVE_INFINITY)
  }).pipe(Effect.tx)
Referenced by 1 symbols