<A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>Creates a new dropping TxQueue with the specified capacity that drops new items when full.
Details
This function returns a new TxQueue reference with dropping strategy. No existing TxQueue instances are modified.
Example (Creating dropping queues)
import { Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
// Create a dropping queue with capacity 2
const queue = yield* TxQueue.dropping<number>(2)
// Fill to capacity
yield* TxQueue.offer(queue, 1)
yield* TxQueue.offer(queue, 2)
// This will be dropped (returns false)
const accepted = yield* TxQueue.offer(queue, 3)
console.log(accepted) // false
})export const const dropping: <A = never, E = never>(
capacity: number
) => Effect.Effect<TxQueue<A, E>>
Creates a new dropping TxQueue with the specified capacity that drops new items when full.
Details
This function returns a new TxQueue reference with dropping strategy. No existing TxQueue instances are modified.
Example (Creating dropping queues)
import { Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
// Create a dropping queue with capacity 2
const queue = yield* TxQueue.dropping<number>(2)
// Fill to capacity
yield* TxQueue.offer(queue, 1)
yield* TxQueue.offer(queue, 2)
// This will be dropped (returns false)
const accepted = yield* TxQueue.offer(queue, 3)
console.log(accepted) // false
})
dropping = <function (type parameter) A in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>A = never, function (type parameter) E in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>E = never>(
capacity: numbercapacity: number
): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface TxQueue<in out A, in out E = never>Namespace containing type definitions for TxQueue variance annotations.
A TxQueue represents a transactional queue data structure that provides both
enqueue and dequeue operations with Software Transactional Memory (STM) semantics.
Example (Combining enqueue and dequeue operations)
import { Effect, TxQueue } from "effect"
const program = Effect.gen(function*() {
// Create a bounded transactional queue (E defaults to never)
const queue = yield* TxQueue.bounded<number>(10)
// Single operations - automatically transactional
const accepted = yield* TxQueue.offer(queue, 42)
const item = yield* TxQueue.take(queue) // Effect<number, never>
console.log(item) // 42
// Queue with error channel
const faultTolerantQueue = yield* TxQueue.bounded<number, string>(10)
// Operations can handle queue-level failures
yield* TxQueue.fail(faultTolerantQueue, "queue failed")
const result = yield* Effect.flip(TxQueue.take(faultTolerantQueue))
console.log(result) // "queue failed"
})
TxQueue<function (type parameter) A in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>A, function (type parameter) E in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>E>> =>
import EffectEffect.gen(function*() {
const const items: TxChunk.TxChunk<A>const 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.empty<function (type parameter) A in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>A>()
const const stateRef: TxRef.TxRef<State<A, E>>const 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 = yield* import TxRefTxRef.const make: <State<A, E>>(initial: State<A, E>) => anyCreates a new TxRef with the specified initial value.
When to use
Use to create a TxRef inside an Effect workflow.
Example (Creating transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
// Create a transactional reference with initial value
const counter = yield* TxRef.make(0)
const name = yield* TxRef.make("Alice")
// Use in transactions
yield* Effect.tx(Effect.gen(function*() {
yield* TxRef.set(counter, 42)
yield* TxRef.set(name, "Bob")
}))
console.log(yield* TxRef.get(counter)) // 42
console.log(yield* TxRef.get(name)) // "Bob"
})
make<type State<_A, E> =
| {
readonly _tag: "Open"
}
| {
readonly _tag: "Closing"
readonly cause: Cause.Cause<E>
}
| {
readonly _tag: "Done"
readonly cause: Cause.Cause<E>
}
Represents the state of a transactional queue with sophisticated lifecycle management.
Details
The queue progresses through three states:
- Open: Accepting offers and serving takes normally
- Closing: No new offers accepted, serving remaining items until empty
- Done: Terminal state with completion cause, no further operations possible
Example (Inspecting queue lifecycle states)
import type { TxQueue } from "effect"
// State progression example
declare const state: TxQueue.State<string, Error>
if (state._tag === "Open") {
console.log("Queue is accepting new items")
} else if (state._tag === "Closing") {
console.log("Queue is draining, cause:", state.cause)
} else {
console.log("Queue is done, cause:", state.cause)
}
State<function (type parameter) A in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>A, function (type parameter) E in <A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>E>>({ _tag: "Open"_tag: "Open" })
const const txQueue: anytxQueue = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const TxQueueProto: {
"~effect/transactions/TxQueue/Enqueue": {
_A: (_: never) => never
_E: (_: never) => never
}
"~effect/transactions/TxQueue/Dequeue": {
_A: (_: never) => never
_E: (_: never) => never
}
"~effect/transactions/TxQueue": {
_A: (_: never) => never
_E: (_: never) => never
}
[NodeInspectSymbol](
this: TxQueue<unknown, unknown>
): unknown
toString(
this: TxQueue<unknown, unknown>
): string
toJSON(this: TxQueue<unknown, unknown>): {
_id: string
strategy:
| "bounded"
| "unbounded"
| "dropping"
| "sliding"
capacity: number
}
}
TxQueueProto)
const txQueue: anytxQueue.strategy = "dropping"
const txQueue: anytxQueue.capacity = capacity: numbercapacity
const txQueue: anytxQueue.items = const items: TxChunk.TxChunk<A>const 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
const txQueue: anytxQueue.stateRef = const stateRef: TxRef.TxRef<State<A, E>>const 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
return const txQueue: anytxQueue
}).pipe(import EffectEffect.tx)