<A, E>(self: TxEnqueue<A, E | Cause.Done>): Effect.Effect<boolean>Ends a queue by signaling completion with a Cause.Done error.
Details
This is a convenience wrapper around failCause for queues whose error channel can contain Cause.Done. If buffered items remain, the queue enters the closing state and those items may still be consumed before later take or peek operations fail with Cause.Done.
Example (Ending queues)
import { Cause, Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* TxQueue.bounded<number, Cause.Done>(10)
// Signal the end of the queue
const result = yield* TxQueue.end(queue)
console.log(result) // true
// All operations will now fail with Done
const takeResult = yield* Effect.flip(TxQueue.take(queue))
console.log(Cause.isDone(takeResult)) // true
const peekResult = yield* Effect.flip(TxQueue.peek(queue))
console.log(Cause.isDone(peekResult)) // true
})export const const end: <A, E>(
self: TxEnqueue<A, E | Cause.Done>
) => Effect.Effect<boolean>
Ends a queue by signaling completion with a Cause.Done error.
Details
This is a convenience wrapper around failCause for queues whose error channel can contain Cause.Done. If buffered items remain, the queue enters the closing state and those items may still be consumed before later take or peek operations fail with Cause.Done.
Example (Ending queues)
import { Cause, Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* TxQueue.bounded<number, Cause.Done>(10)
// Signal the end of the queue
const result = yield* TxQueue.end(queue)
console.log(result) // true
// All operations will now fail with Done
const takeResult = yield* Effect.flip(TxQueue.take(queue))
console.log(Cause.isDone(takeResult)) // true
const peekResult = yield* Effect.flip(TxQueue.peek(queue))
console.log(Cause.isDone(peekResult)) // true
})
end = <function (type parameter) A in <A, E>(self: TxEnqueue<A, E | Cause.Done>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxEnqueue<A, E | Cause.Done>): Effect.Effect<boolean>E>(self: TxEnqueue<A, E | Cause.Done>(parameter) self: {
strategy: "bounded" | "unbounded" | "dropping" | "sliding";
capacity: number;
items: TxChunk.TxChunk<any>;
stateRef: TxRef.TxRef<State<any, any>>;
toString: () => string;
toJSON: () => unknown;
}
self: interface TxEnqueue<in A, in E = never>Namespace containing type definitions for TxEnqueue variance annotations.
A TxEnqueue represents the write-only interface of a transactional queue, providing
operations for adding elements (enqueue operations) and inspecting queue state.
Example (Offering values through enqueue handles)
import { Effect, TxQueue } from "effect"
import type { Cause } from "effect"
const program = Effect.gen(function*() {
// Queue without error channel
const queue = yield* TxQueue.bounded<number>(10)
const accepted = yield* TxQueue.offer(queue, 42)
// Queue with error channel for completion signaling
const faultTolerantQueue = yield* TxQueue.bounded<number, string>(10)
yield* TxQueue.offerAll(faultTolerantQueue, [1, 2, 3])
yield* TxQueue.fail(faultTolerantQueue, "processing complete")
// Works with Done for clean completion
const completableQueue = yield* TxQueue.bounded<
string,
Cause.Done
>(5)
yield* TxQueue.offer(completableQueue, "task")
yield* TxQueue.end(completableQueue)
})
TxEnqueue<function (type parameter) A in <A, E>(self: TxEnqueue<A, E | Cause.Done>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxEnqueue<A, E | Cause.Done>): Effect.Effect<boolean>E | import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done>): import EffectEffect.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> =>
const failCause: {
<E>(cause: Cause.Cause<E>): <A>(
self: TxEnqueue<A, E>
) => Effect.Effect<boolean>
<A, E>(
self: TxEnqueue<A, E>,
cause: Cause.Cause<E>
): Effect.Effect<boolean>
}
failCause(self: TxEnqueue<A, E | Cause.Done>(parameter) self: {
strategy: "bounded" | "unbounded" | "dropping" | "sliding";
capacity: number;
items: TxChunk.TxChunk<any>;
stateRef: TxRef.TxRef<State<any, any>>;
toString: () => string;
toJSON: () => unknown;
}
self, import CauseCause.const fail: <E>(error: E) => Cause<E>Creates a Cause containing a single Fail reason with the
given typed error.
When to use
Use to construct a cause from an expected typed error.
Example (Creating a fail cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
fail(import CauseCause.const Done: <A = void>(
value?: A
) => Done<A>
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done()))