<A, E>(self: Queue<A, E>): Dequeue<A, E>Narrows a Queue to a Dequeue, exposing the consumer side of the queue.
When to use
Use to pass a queue to code that should consume values while keeping producer-side operations out of that code's TypeScript type.
Gotchas
This is a type-level narrowing operation. It returns the same queue object and does not create a runtime wrapper.
export const const asDequeue: <A, E>(
self: Queue<A, E>
) => Dequeue<A, E>
Narrows a Queue to a Dequeue, exposing the consumer side of the queue.
When to use
Use to pass a queue to code that should consume values while keeping
producer-side operations out of that code's TypeScript type.
Gotchas
This is a type-level narrowing operation. It returns the same queue object
and does not create a runtime wrapper.
asDequeue: <function (type parameter) A in <A, E>(self: Queue<A, E>): Dequeue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Dequeue<A, E>E>(self: Queue<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 Queue<in out A, in out E = never>A Queue is an asynchronous queue that can be offered to and taken from.
Details
It also supports signaling that it is done or failed.
Example (Offering and taking queue values)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
// Create a bounded queue
const queue = yield* Queue.bounded<string>(10)
// Producer: offer items to the queue
yield* Queue.offer(queue, "hello")
yield* Queue.offerAll(queue, ["world", "!"])
// Consumer: take items from the queue
const item1 = yield* Queue.take(queue)
const item2 = yield* Queue.take(queue)
const item3 = yield* Queue.take(queue)
console.log([item1, item2, item3]) // ["hello", "world", "!"]
})
Companion namespace containing type-level metadata and low-level state types
for Queue.
Queue<function (type parameter) A in <A, E>(self: Queue<A, E>): Dequeue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Dequeue<A, E>E>) => 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: Queue<A, E>): Dequeue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Dequeue<A, E>E> = import identityidentity