<A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>Takes all messages from the queue, until the queue has errored or is done.
Example (Collecting values until completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(5)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Some time later, end the queue
yield* Effect.forkChild(Queue.end(queue))
// Collect all available messages
const messages = yield* Queue.collect(queue)
console.log(messages) // [1, 2, 3, 4, 5]
})export const const collect: <A, E>(
self: Dequeue<A, E | Done>
) => Effect<Array<A>, Pull.ExcludeDone<E>>
Takes all messages from the queue, until the queue has errored or is done.
Example (Collecting values until completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(5)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Some time later, end the queue
yield* Effect.forkChild(Queue.end(queue))
// Collect all available messages
const messages = yield* Queue.collect(queue)
console.log(messages) // [1, 2, 3, 4, 5]
})
collect = <function (type parameter) A in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>E>(self: Dequeue<A, E | Done>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self: interface Dequeue<out A, out E = never>A Dequeue is a queue that can be taken from.
Details
This interface represents the read-only part of a Queue, allowing you to take
elements from the queue but not offer elements to it.
Example (Taking through dequeue handles)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string, never>(10)
// A Dequeue can only take elements
const dequeue: Queue.Dequeue<string> = queue
// Pre-populate the queue
yield* Queue.offerAll(queue, ["a", "b", "c"])
// Take elements using dequeue interface
const item = yield* Queue.take(dequeue)
console.log(item) // "a"
})
Companion namespace containing type-level metadata for the Dequeue
read-only queue interface.
Dequeue<function (type parameter) A in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>E | import DoneDone>): import EffectEffect<interface Array<T>Array<function (type parameter) A in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>A>, import PullPull.type Pull.ExcludeDone = /*unresolved*/ anyExcludeDone<function (type parameter) E in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>E>> =>
import internalEffectinternalEffect.const suspend: <A, E, R>(
evaluate: LazyArg<Effect.Effect<A, E, R>>
) => Effect.Effect<A, E, R>
suspend(() => {
const const out: anyout = import ArrArr.empty<function (type parameter) A in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>A>()
return import internalEffectinternalEffect.const as: {
<A, B>(value: B): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E, R>
<A, E, R, B>(
self: Effect.Effect<A, E, R>,
value: B
): Effect.Effect<B, E, R>
}
as(
import PullPull.catchDone(
import internalEffectinternalEffect.const whileLoop: <A, E, R>(options: {
readonly while: LazyArg<boolean>
readonly body: LazyArg<Effect.Effect<A, E, R>>
readonly step: (a: A) => void
}) => Effect.Effect<void, E, R>
whileLoop({
while: LazyArg<boolean>while: import constTrueconstTrue,
body: LazyArg<
Effect<[A, ...A[]], Done<void> | E, never>
>
body: import constantconstant(const takeAll: <A, E>(
self: Dequeue<A, E>
) => Effect<Arr.NonEmptyArray<A>, E>
Takes all currently available messages, waiting until at least one message
is available when the queue is empty.
When to use
Use when consumers should process the next non-empty batch of buffered
messages instead of repeatedly taking one message at a time.
Details
Returns a non-empty array. If the queue completes or fails before a message
can be taken, the effect fails with the queue's terminal error.
Example (Taking all available values)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(5)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Take all available messages
const messages1 = yield* Queue.takeAll(queue)
console.log(messages1) // [1, 2, 3, 4, 5]
})
takeAll(self: Dequeue<A, E | Done>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self)),
step: (items: Arr.NonEmptyArray<A>) => voidstep(items: Arr.NonEmptyArray<A>(parameter) items: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
items: import ArrArr.type Arr.NonEmptyArray = /*unresolved*/ anyNonEmptyArray<function (type parameter) A in <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>>A>) {
for (let let i: numberi = 0; let i: numberi < items: Arr.NonEmptyArray<A>(parameter) items: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
items.length; let i: numberi++) {
const out: anyout.push(items: Arr.NonEmptyArray<A>(parameter) items: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => A | undefined;
push: (...items: Array<A>) => number;
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
reverse: () => Array<A>;
shift: () => A | undefined;
slice: (start?: number, end?: number) => Array<A>;
sort: (compareFn?: ((a: A, b: A) => number) | undefined) => [A, ...A[]];
splice: { (start: number, deleteCount?: number): Array<A>; (start: number, deleteCount: number, ...items: Array<A>): Array<A> };
unshift: (...items: Array<A>) => number;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): this is S[]; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: Array<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: Array<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: Array<A>) => A, initialValue: A): A; (callbackfn: (previousVa…;
find: { (predicate: (value: A, index: number, obj: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: Array<A>) => unknown, thisArg?: any) => number;
fill: (value: A, start?: number, end?: number) => [A, ...A[]];
copyWithin: (target: number, start: number, end?: number) => [A, ...A[]];
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: Array<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: Array<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
items[let i: numberi])
}
}
}),
() => import internalEffectinternalEffect.const void: Effect<void, never, never>(alias) const void: {
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;
}
void
),
const out: anyout
)
}) as any