(max: number): <A>(self: Subscription<A>) => Effect.Effect<Array<A>>
<A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>Takes up to the specified number of messages from the subscription without suspending.
Example (Taking up to a maximum number of messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish multiple messages
yield* PubSub.publishAll(pubsub, ["msg1", "msg2", "msg3", "msg4", "msg5"])
// Take up to 3 messages
const upTo3 = yield* PubSub.takeUpTo(subscription, 3)
console.log("Up to 3:", upTo3) // ["msg1", "msg2", "msg3"]
// Take up to 5 more (only 2 remaining)
const upTo5 = yield* PubSub.takeUpTo(subscription, 5)
console.log("Up to 5:", upTo5) // ["msg4", "msg5"]
// No more messages available
const noMore = yield* PubSub.takeUpTo(subscription, 10)
console.log("No more:", noMore) // []
}))
})export const const takeUpTo: {
(max: number): <A>(
self: Subscription<A>
) => Effect.Effect<Array<A>>
<A>(
self: Subscription<A>,
max: number
): Effect.Effect<Array<A>>
}
Takes up to the specified number of messages from the subscription without suspending.
Example (Taking up to a maximum number of messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish multiple messages
yield* PubSub.publishAll(pubsub, ["msg1", "msg2", "msg3", "msg4", "msg5"])
// Take up to 3 messages
const upTo3 = yield* PubSub.takeUpTo(subscription, 3)
console.log("Up to 3:", upTo3) // ["msg1", "msg2", "msg3"]
// Take up to 5 more (only 2 remaining)
const upTo5 = yield* PubSub.takeUpTo(subscription, 5)
console.log("Up to 5:", upTo5) // ["msg4", "msg5"]
// No more messages available
const noMore = yield* PubSub.takeUpTo(subscription, 10)
console.log("No more:", noMore) // []
}))
})
takeUpTo: {
(max: numbermax: number): <function (type parameter) A in <A>(self: Subscription<A>): Effect.Effect<Array<A>>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>): Effect.Effect<Array<A>>A>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Array<T>Array<function (type parameter) A in <A>(self: Subscription<A>): Effect.Effect<Array<A>>A>>
<function (type parameter) A in <A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>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>, max: number): Effect.Effect<Array<A>>A>, max: numbermax: number): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Array<T>Array<function (type parameter) A in <A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>A>>
} = import dualdual(2, <function (type parameter) A in <A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>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>, max: number): Effect.Effect<Array<A>>A>, max: numbermax: number): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Array<T>Array<function (type parameter) A in <A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>A>> =>
import EffectEffect.suspend(() => {
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 EffectEffect.interrupt
let let replay: A[] | undefinedreplay: interface Array<T>Array<function (type parameter) A in <A>(self: Subscription<A>, max: number): Effect.Effect<Array<A>>A> | undefined = var undefinedundefined
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<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 >= max: numbermax) {
return import EffectEffect.succeed(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>.takeN(n: number): A[]takeN(max: numbermax))
} else 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<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 > 0) {
let replay: A[] | undefinedreplay = 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>.takeAll(): A[]takeAll()
max: numbermax = max: numbermax - let replay: A[]replay.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length
}
const const as: A[]as = 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>.pollers: MutableList.MutableList<Deferred.Deferred<any>>(property) Subscription<out A>.pollers: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
pollers.length === 0
? 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>.pollUpTo(n: number): A[]pollUpTo(max: numbermax)
: []
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>.strategy: PubSub.Strategy<any>(property) Subscription<out A>.strategy: {
shutdown: Effect.Effect<void>;
handleSurplus: (pubsub: PubSub.Atomic<any>, subscribers: PubSub.Subscribers<any>, elements: Iterable<any>, isShutdown: MutableRef.MutableRef<boolean>) => Effect.Effect<boolean>;
onPubSubEmptySpaceUnsafe: (pubsub: PubSub.Atomic<any>, subscribers: PubSub.Subscribers<any>) => void;
completePollersUnsafe: (pubsub: PubSub.Atomic<any>, subscribers: PubSub.Subscribers<any>, subscription: PubSub.BackingSubscription<any>, pollers: MutableList.MutableList<Deferred.Deferred<any, never>>) => void;
completeSubscribersUnsafe: (pubsub: PubSub.Atomic<any>, subscribers: PubSub.Subscribers<any>) => void;
}
strategy.PubSub<in out A>.Strategy<any>.onPubSubEmptySpaceUnsafe(pubsub: PubSub<in out A>.Atomic<any>, subscribers: PubSub.Subscribers<any>): voidDescribes how subscribers should signal to publishers waiting for space
to become available in the PubSub that space may be available.
onPubSubEmptySpaceUnsafe(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>.pubsub: PubSub.Atomic<any>(property) Subscription<out A>.pubsub: {
capacity: number;
isEmpty: () => boolean;
isFull: () => boolean;
size: () => number;
publish: (value: any) => boolean;
publishAll: (elements: Iterable<any>) => Array<any>;
slide: () => void;
subscribe: () => PubSub.BackingSubscription<any>;
replayWindow: () => PubSub.ReplayWindow<any>;
}
pubsub, 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>.subscribers: PubSub.Subscribers<any>(property) Subscription<out A>.subscribers: {
clear: () => void;
delete: (key: PubSub.BackingSubscription<any>) => boolean;
forEach: (callbackfn: (value: Set<MutableList.MutableList<Deferred.Deferred<any, never>>>, key: PubSub.BackingSubscription<any>, map: Map<PubSub.BackingSubscription<any>, Set<MutableList.MutableList<Deferred.Deferred<any, never>>>>) => void, thisAr…;
get: (key: PubSub.BackingSubscription<any>) => Set<MutableList.MutableList<Deferred.Deferred<any, never>>> | undefined;
has: (key: PubSub.BackingSubscription<any>) => boolean;
set: (key: PubSub.BackingSubscription<any>, value: Set<MutableList.MutableList<Deferred.Deferred<any, never>>>) => PubSub.Subscribers<any>;
size: number;
entries: () => MapIterator<[PubSub.BackingSubscription<any>, Set<MutableList.MutableList<Deferred.Deferred<any, never>>>]>;
keys: () => MapIterator<PubSub.BackingSubscription<any>>;
values: () => MapIterator<Set<MutableList.MutableList<Deferred.Deferred<any, never>>>>;
}
subscribers)
return let replay: A[] | undefinedreplay ? import EffectEffect.succeed(let replay: A[]replay.Array<A>.concat(...items: ConcatArray<A>[]): A[] (+1 overload)Combines two or more arrays.
This method returns a new array without modifying any existing arrays.
concat(const as: A[]as)) : import EffectEffect.succeed(const as: A[]as)
}))