<A, E>(self: Queue<A, E>): Enqueue<A, E>Converts a Queue to its write-only Enqueue interface.
When to use
Use to expose only the producer side of a Queue to code that should offer
values or signal queue lifecycle.
Gotchas
This is a type-level capability restriction. It returns the same queue object, so it does not hide read operations at runtime.
export const const asEnqueue: <A, E>(
self: Queue<A, E>
) => Enqueue<A, E>
Converts a Queue to its write-only Enqueue interface.
When to use
Use to expose only the producer side of a Queue to code that should offer
values or signal queue lifecycle.
Gotchas
This is a type-level capability restriction. It returns the same queue
object, so it does not hide read operations at runtime.
asEnqueue = <function (type parameter) A in <A, E>(self: Queue<A, E>): Enqueue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Enqueue<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>): Enqueue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Enqueue<A, E>E>): interface Enqueue<in A, in E = never>An Enqueue is a queue that can be offered to.
Details
This interface represents the write-only part of a Queue, allowing you to offer
elements to the queue but not take elements from it.
Example (Offering through enqueue handles)
import { Effect, Queue } from "effect"
// Function that only needs write access to a queue
const producer = (enqueue: Queue.Enqueue<string>) =>
Effect.gen(function*() {
yield* Queue.offer(enqueue, "hello")
yield* Queue.offerAll(enqueue, ["world", "!"])
})
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string>(10)
yield* producer(queue)
})
Companion namespace containing type-level metadata for the Enqueue
write-only queue interface.
Enqueue<function (type parameter) A in <A, E>(self: Queue<A, E>): Enqueue<A, E>A, function (type parameter) E in <A, E>(self: Queue<A, E>): Enqueue<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