effect-io-ai

Package: effect
Module: TxPubSub

TxPubSub.dropping

Creates a dropping TxPubSub with the specified capacity. When a subscriber’s queue is full, the message is dropped for that subscriber.

Example (Creating a dropping pub/sub)

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

const program = Effect.gen(function*() {
  const hub = yield* TxPubSub.dropping<number>(2)

  yield* Effect.scoped(
    Effect.gen(function*() {
      const sub = yield* TxPubSub.subscribe(hub)
      yield* TxPubSub.publish(hub, 1)
      yield* TxPubSub.publish(hub, 2)
      yield* TxPubSub.publish(hub, 3) // dropped
      const v1 = yield* TxQueue.take(sub)
      const v2 = yield* TxQueue.take(sub)
      console.log(v1, v2) // 1 2
    })
  )
})

Signature

declare const dropping: <A = never>(capacity: number) => Effect.Effect<TxPubSub<A>>

Source

Since v2.0.0