Hyperlinkv0.8.0-beta.28

PubSub

PubSub.sizeUnsafeconsteffect/PubSub.ts:643
<A>(self: PubSub<A>): number

Returns the current number of messages retained by the PubSub for active subscribers synchronously.

When to use

Use when an immediate PubSub size snapshot is needed outside effectful code and concurrent changes between the check and later use are acceptable.

Details

Returns 0 after shutdown. Because this is an unsafe synchronous snapshot, prefer size in effectful code.

Example (Reading size synchronously)

import { PubSub } from "effect"

// Unsafe synchronous size check
declare const pubsub: PubSub.PubSub<string>

const size = PubSub.sizeUnsafe(pubsub)
console.log("Current size:", size)
getters
Source effect/PubSub.ts:6436 lines
export const sizeUnsafe = <A>(self: PubSub<A>): number => {
  if (MutableRef.get(self.shutdownFlag)) {
    return 0
  }
  return self.pubsub.size()
}
Referenced by 1 symbols