<A, E>(self: Enqueue<A, E>): Effect<boolean>Shuts down the queue immediately, discarding buffered messages and resuming pending operations.
Details
The operation is idempotent and returns true, including when the queue has
already been shut down or completed.
Example (Shutting down queues)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number>(2)
// Add messages
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
// Shutdown clears buffered messages and prevents further offers
const wasShutdown = yield* Queue.shutdown(queue)
console.log(wasShutdown) // true
// Queue is now done and cleared
const size = yield* Queue.size(queue)
console.log(size) // 0
})export const const shutdown: <A, E>(
self: Enqueue<A, E>
) => Effect<boolean>
Shuts down the queue immediately, discarding buffered messages and resuming
pending operations.
Details
The operation is idempotent and returns true, including when the queue has
already been shut down or completed.
Example (Shutting down queues)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number>(2)
// Add messages
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
// Shutdown clears buffered messages and prevents further offers
const wasShutdown = yield* Queue.shutdown(queue)
console.log(wasShutdown) // true
// Queue is now done and cleared
const size = yield* Queue.size(queue)
console.log(size) // 0
})
shutdown = <function (type parameter) A in <A, E>(self: Enqueue<A, E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>): Effect<boolean>E>(self: Enqueue<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 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: Enqueue<A, E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>): Effect<boolean>E>): interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean> =>
import internalEffectinternalEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect.Effect<A>
sync(() => {
if (self: Enqueue<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.Enqueue<in A, in E = never>.state: Queue.State<any, any>state._tag: "Open" | "Closing" | "Done"_tag === "Done") {
return true
}
import MutableListMutableList.const clear: <A>(
self: MutableList<A>
) => void
Removes all elements from the MutableList, resetting it to an empty state.
This operation is highly optimized and releases all internal memory.
Example (Clearing a mutable list)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.appendAll(list, [1, 2, 3, 4, 5])
console.log(list.length) // 5
// Clear all elements
MutableList.clear(list)
console.log(list.length) // 0
console.log(MutableList.take(list)) // Empty
// Can still use the list after clearing
MutableList.append(list, 42)
console.log(list.length) // 1
// Useful for resetting queues or buffers
function resetBuffer<T>(buffer: MutableList.MutableList<T>) {
MutableList.clear(buffer)
console.log("Buffer cleared and ready for reuse")
}
clear(self: Enqueue<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.Enqueue<in A, in E = never>.messages: MutableList.MutableList<any>(property) Enqueue<in A, in E = never>.messages: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
messages)
const const offers: Set<Queue.OfferEntry<any>>offers = self: Enqueue<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.Enqueue<in A, in E = never>.state: {
readonly _tag: "Open";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
} | {
readonly _tag: "Closing";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
readonly exit: Failure<never, any>;
}
state.offers: Set<Queue.OfferEntry<any>>offers
const finalize: <A, E>(
self: Enqueue<A, E> | Dequeue<A, E>,
exit: Failure<never, E>
) => void
finalize(self: Enqueue<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, self: Enqueue<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.Enqueue<in A, in E = never>.state: {
readonly _tag: "Open";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
} | {
readonly _tag: "Closing";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
readonly exit: Failure<never, any>;
}
state._tag: "Open" | "Closing"_tag === "Open" ? const exitInterrupt: Failure<never, never>const exitInterrupt: {
_tag: "Failure";
cause: Cause.Cause<E>;
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;
}
exitInterrupt : self: Enqueue<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.Enqueue<in A, in E = never>.state: {
readonly _tag: "Closing";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
readonly exit: Failure<never, any>;
}
state.exit: Failure<never, E>(property) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
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;
}
exit)
if (const offers: Set<Queue.OfferEntry<any>>offers.Set<T>.size: numbersize > 0) {
for (const const entry: Queue.OfferEntry<any>entry of const offers: Set<Queue.OfferEntry<any>>offers) {
if (const entry: Queue.OfferEntry<any>entry._tag: "Array" | "Single"_tag === "Single") {
const entry: {
readonly _tag: "Single"
readonly message: any
readonly resume: (_: Effect<boolean>) => void
}
entry.resume: (_: Effect<boolean>) => voidresume(const exitFalse: Exit<boolean, never>exitFalse)
} else {
const entry: {
readonly _tag: "Array"
readonly remaining: any[]
offset: number
readonly resume: (
_: Effect<any[], never, never>
) => void
}
entry.resume: (_: Effect<Array<A>>) => voidresume(import corecore.const exitSucceed: <A>(
a: A
) => Exit.Exit<A>
exitSucceed(const entry: {
readonly _tag: "Array"
readonly remaining: any[]
offset: number
readonly resume: (
_: Effect<any[], never, never>
) => void
}
entry.remaining: any[]remaining.Array<any>.slice(start?: number, end?: number): any[]Returns a copy of a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
slice(const entry: {
readonly _tag: "Array"
readonly remaining: any[]
offset: number
readonly resume: (
_: Effect<any[], never, never>
) => void
}
entry.offset: numberoffset)))
}
}
const offers: Set<Queue.OfferEntry<any>>offers.Set<Queue<in out A, in out E = never>.OfferEntry<any>>.clear(): voidclear()
}
return true
})