Package: effect
Module: PubSub
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
}
See
remaining for the effectful variant that interrupts on shutdownSignature
declare const remainingUnsafe: <A>(self: Subscription<A>) => Option.Option<number>
Since v4.0.0