<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
}export const const remainingUnsafe: <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
}
remainingUnsafe = <function (type parameter) A in <A>(self: Subscription<A>): Option.Option<number>A>(self: Subscription<A>(parameter) self: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface Subscription<out A>A subscription represents a consumer's connection to a PubSub, allowing them to take messages.
Example (Taking messages from a subscription)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Subscribe within a scope for automatic cleanup
yield* Effect.scoped(Effect.gen(function*() {
const subscription: PubSub.Subscription<string> = yield* PubSub.subscribe(
pubsub
)
yield* PubSub.publishAll(pubsub, ["msg1", "msg2", "msg3"])
// Take individual messages
const message = yield* PubSub.take(subscription)
console.log(message) // "msg1"
// Take multiple messages
const messages = yield* PubSub.takeUpTo(subscription, 1)
console.log(messages) // ["msg2"]
const allMessages = yield* PubSub.takeAll(subscription)
console.log(allMessages) // ["msg3"]
}))
})
Subscription<function (type parameter) A in <A>(self: Subscription<A>): Option.Option<number>A>): import OptionOption.type Option.Option = /*unresolved*/ anyOption<number> => {
if (self: Subscription<A>(parameter) self: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.Subscription<out A>.shutdownFlag: MutableRef.MutableRef<boolean>(property) Subscription<out A>.shutdownFlag: {
current: T;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
shutdownFlag.current) {
return import OptionOption.none()
}
return import OptionOption.some(self: Subscription<A>(parameter) self: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.Subscription<A>.subscription: PubSub.BackingSubscription<A>(property) Subscription<A>.subscription: {
isEmpty: () => boolean;
size: () => number;
poll: () => typeof MutableList.Empty | A;
pollUpTo: (n: number) => Array<A>;
unsubscribe: () => void;
}
subscription.PubSub<in out A>.BackingSubscription<A>.size(): numbersize() + self: Subscription<A>(parameter) self: {
pubsub: PubSub.Atomic<any>;
subscribers: PubSub.Subscribers<any>;
subscription: PubSub.BackingSubscription<A>;
pollers: MutableList.MutableList<Deferred.Deferred<any>>;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<any>;
replayWindow: PubSub.ReplayWindow<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.Subscription<A>.replayWindow: PubSub.ReplayWindow<A>(property) Subscription<A>.replayWindow: {
take: () => A | undefined;
takeN: (n: number) => Array<A>;
takeAll: () => Array<A>;
remaining: number;
}
replayWindow.PubSub<in out A>.ReplayWindow<A>.remaining: numberremaining)
}