Hyperlinkv0.8.0-beta.28

PubSub

PubSub.remainingUnsafeconsteffect/PubSub.ts:1470
<A>(self: Subscription<A>): Option.Option<number>

Synchronously returns the number of messages currently available in the subscription, or Option.none() when it is shut down.

When to use

Use when you need synchronous polling outside a managed workflow and want shutdown observed as data instead of interruption.

Example (Checking remaining messages synchronously)

import { PubSub } from "effect"

declare const subscription: PubSub.Subscription<string>

// Unsafe synchronous check for remaining messages
const remainingOption = PubSub.remainingUnsafe(subscription)
if (remainingOption._tag === "Some") {
  console.log("Messages available:", remainingOption.value)
} else {
  console.log("Subscription is shutdown")
}

// Useful for polling or batching scenarios
if (remainingOption._tag === "Some" && remainingOption.value > 10) {
  // Process messages in batch
}
gettersremaining
Source effect/PubSub.ts:14706 lines
export const remainingUnsafe = <A>(self: Subscription<A>): Option.Option<number> => {
  if (self.shutdownFlag.current) {
    return Option.none()
  }
  return Option.some(self.subscription.size() + self.replayWindow.remaining)
}