Hyperlinkv0.8.0-beta.28

PubSub

PubSub.isFullconsteffect/PubSub.ts:687
<A>(self: PubSub<A>): Effect.Effect<boolean>

Returns true when the PubSub has reached its configured capacity.

Details

For unbounded PubSubs this is normally false.

Example (Checking whether a PubSub is full)

import { Effect, PubSub } from "effect"

const program = Effect.gen(function*() {
  const pubsub = yield* PubSub.bounded<string>(2)

  // Initially not full
  const initiallyFull = yield* PubSub.isFull(pubsub)
  console.log("Initially full:", initiallyFull) // false

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

    // Fill the PubSub for the active subscription
    yield* PubSub.publish(pubsub, "msg1")
    yield* PubSub.publish(pubsub, "msg2")

    const nowFull = yield* PubSub.isFull(pubsub)
    console.log("Now full:", nowFull) // true

    yield* PubSub.takeAll(subscription)
  }))
})
predicates
Source effect/PubSub.ts:6872 lines
export const isFull = <A>(self: PubSub<A>): Effect.Effect<boolean> =>
  Effect.map(size(self), (size) => size === self.pubsub.capacity)