<A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>Removes and returns all currently buffered elements without changing the queue state.
Details
If the queue is already done with a Cause.Done error, returns an empty array. If the queue is done for any other cause, including interruption or failure, that cause is propagated.
Example (Clearing queues)
import { Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* TxQueue.bounded<number>(10)
yield* TxQueue.offerAll(queue, [1, 2, 3, 4, 5])
const sizeBefore = yield* TxQueue.size(queue)
console.log(sizeBefore) // 5
const cleared = yield* TxQueue.clear(queue)
console.log(cleared) // [1, 2, 3, 4, 5]
const sizeAfter = yield* TxQueue.size(queue)
console.log(sizeAfter) // 0
})export const const clear: <A, E>(
self: TxEnqueue<A, E>
) => Effect.Effect<Array<A>, ExcludeDone<E>>
Removes and returns all currently buffered elements without changing the
queue state.
Details
If the queue is already done with a Cause.Done error, returns an empty array. If the queue is done for any other cause, including interruption or failure, that cause is propagated.
Example (Clearing queues)
import { Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* TxQueue.bounded<number>(10)
yield* TxQueue.offerAll(queue, [1, 2, 3, 4, 5])
const sizeBefore = yield* TxQueue.size(queue)
console.log(sizeBefore) // 5
const cleared = yield* TxQueue.clear(queue)
console.log(cleared) // [1, 2, 3, 4, 5]
const sizeAfter = yield* TxQueue.size(queue)
console.log(sizeAfter) // 0
})
clear = <function (type parameter) A in <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>E>(self: TxEnqueue<A, E>(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>): Effect.Effect<Array<A>, ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>E>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Array<T>Array<function (type parameter) A in <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>A>, import ExcludeDoneExcludeDone<function (type parameter) E in <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>>E>> =>
import EffectEffect.gen(function*() {
const const state: State<any, any>state = yield* import TxRefTxRef.const get: <A>(
self: TxRef<A>
) => Effect.Effect<A>
Reads the current value of the TxRef.
When to use
Use to read the current value of a TxRef.
Example (Reading transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
const counter = yield* TxRef.make(42)
// Read the value within a transaction
const value = yield* Effect.tx(
TxRef.get(counter)
)
console.log(value) // 42
})
get(self: TxEnqueue<A, E>(parameter) self: {
strategy: "bounded" | "unbounded" | "dropping" | "sliding";
capacity: number;
items: TxChunk.TxChunk<any>;
stateRef: TxRef.TxRef<State<any, any>>;
toString: () => string;
toJSON: () => unknown;
}
self.TxQueueState.stateRef: TxRef.TxRef<State<any, any>>(property) TxQueueState.stateRef: {
version: number;
pending: Map<unknown, () => void>;
value: A;
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; <…;
}
stateRef)
if (const state: State<any, any>state._tag === "Done") {
// Return empty array only for halt causes (like Cause.Done)
if (import isDoneCauseisDoneCause(const state: anyconst state: {
_tag: "Done";
cause: Cause.Cause<E>;
}
state.cause)) {
return []
}
return yield* import EffectEffect.failCause(const state: anyconst state: {
_tag: "Done";
cause: Cause.Cause<E>;
}
state.cause)
}
const const chunk: Chunk.Chunk<any>const chunk: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
chunk = yield* import TxChunkTxChunk.get(self: TxEnqueue<A, E>(parameter) self: {
strategy: "bounded" | "unbounded" | "dropping" | "sliding";
capacity: number;
items: TxChunk.TxChunk<any>;
stateRef: TxRef.TxRef<State<any, any>>;
toString: () => string;
toJSON: () => unknown;
}
self.TxQueueState.items: TxChunk.TxChunk<any>(property) TxQueueState.items: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
items)
yield* import TxChunkTxChunk.set(self: TxEnqueue<A, E>(parameter) self: {
strategy: "bounded" | "unbounded" | "dropping" | "sliding";
capacity: number;
items: TxChunk.TxChunk<any>;
stateRef: TxRef.TxRef<State<any, any>>;
toString: () => string;
toJSON: () => unknown;
}
self.TxQueueState.items: TxChunk.TxChunk<any>(property) TxQueueState.items: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
items, import ChunkChunk.empty())
return import ChunkChunk.toArray(const chunk: Chunk.Chunk<any>const chunk: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
chunk)
}).pipe(import EffectEffect.tx)