<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)
})export const 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 = <function (type parameter) A in <A, E>(self: Dequeue<A, E>, min: number, max: number): Effect<Array<A>, E>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>, min: number, max: number): Effect<Array<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>, min: number, max: number): Effect<Array<A>, E>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>, min: number, max: number): Effect<Array<A>, E>E>,
min: numbermin: number,
max: numbermax: number
): import EffectEffect<interface Array<T>Array<function (type parameter) A in <A, E>(self: Dequeue<A, E>, min: number, max: number): Effect<Array<A>, E>A>, function (type parameter) E in <A, E>(self: Dequeue<A, E>, min: number, max: number): Effect<Array<A>, E>E> =>
import internalEffectinternalEffect.const suspend: <A, E, R>(
evaluate: LazyArg<Effect.Effect<A, E, R>>
) => Effect.Effect<A, E, R>
suspend(() =>
const takeBetweenUnsafe: <A, E>(
self: Dequeue<A, E>,
min: number,
max: number
) => Exit<Array<A>, E> | undefined
takeBetweenUnsafe(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, min: numbermin, max: numbermax) ?? import internalEffectinternalEffect.const andThen: {
<A, B, E2, R2>(
f: (a: A) => Effect.Effect<B, E2, R2>
): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E | E2, R | R2>
<B, E2, R2>(f: Effect.Effect<B, E2, R2>): <
A,
E,
R
>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (a: A) => Effect.Effect<B, E2, R2>
): Effect.Effect<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: Effect.Effect<B, E2, R2>
): Effect.Effect<B, E | E2, R | R2>
}
andThen(const awaitTake: <A, E>(
self: Dequeue<A, E>
) => Effect<void, E, never>
awaitTake(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), 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, max: numbermax))
)