<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]
})export const 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 = <function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<Arr.NonEmptyArray<A>, E>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Arr.NonEmptyArray<A>, E>E>(self: Dequeue<A, E>(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>): Effect<Arr.NonEmptyArray<A>, E>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Arr.NonEmptyArray<A>, E>E>): import EffectEffect<import ArrArr.type Arr.NonEmptyArray = /*unresolved*/ anyNonEmptyArray<function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<Arr.NonEmptyArray<A>, E>A>, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Arr.NonEmptyArray<A>, E>E> =>
const takeBetween: <A, E>(
self: Dequeue<A, E>,
min: number,
max: number
) => Effect<Array<A>, E>
Takes between min and max messages from the queue.
Details
The operation waits when fewer than the required minimum messages are
available. It returns at most max messages. If the queue completes or fails
before the minimum can be satisfied, the effect fails with the queue's
terminal error.
Example (Taking a bounded batch of values)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number>(10)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5, 6, 7, 8])
// Take between 2 and 5 messages
const batch1 = yield* Queue.takeBetween(queue, 2, 5)
console.log(batch1) // [1, 2, 3, 4, 5] - took 5 (up to max)
// Take between 1 and 10 messages (but only 3 remain)
const batch2 = yield* Queue.takeBetween(queue, 1, 10)
console.log(batch2) // [6, 7, 8] - took 3 (all remaining)
// No more messages available, will wait or return done
// const batch3 = yield* Queue.takeBetween(queue, 1, 3)
})
takeBetween(self: Dequeue<A, E>(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, 1, var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.POSITIVE_INFINITY: numberA value greater than the largest number that can be represented in JavaScript.
JavaScript displays POSITIVE_INFINITY values as infinity.
POSITIVE_INFINITY) as any