TxEnqueue<A, E>Namespace containing type definitions for TxEnqueue variance annotations.
export declare namespace TxEnqueue {
/**
* Variance annotation interface for TxEnqueue contravariance.
*
* @category models
* @since 4.0.0
*/
export interface interface TxEnqueue<in A, in E = never>.Variance<in A, in E>Variance annotation interface for TxEnqueue contravariance.
Variance<in function (type parameter) A in Variance<in A, in E>A, in function (type parameter) E in Variance<in A, in E>E> {
readonly TxEnqueue<in A, in E = never>.Variance<in A, in E>._A: Types.Contravariant<A>_A: import TypesTypes.type Contravariant<A> = (_: A) => voidFunction-type alias encoding contravariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter contravariant in input
position.
Details
Contravariant<A> is assignable to Contravariant<B> when B extends A,
following the supertype direction.
Example (Defining a contravariant phantom type)
import type { Types } from "effect"
interface Consumer<T> {
readonly _phantom: Types.Contravariant<T>
readonly accept: (value: T) => void
}
Namespace for
Contravariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Contravariant.
Contravariant<function (type parameter) A in Variance<in A, in E>A>
readonly TxEnqueue<in A, in E = never>.Variance<in A, in E>._E: Types.Contravariant<E>_E: import TypesTypes.type Contravariant<A> = (_: A) => voidFunction-type alias encoding contravariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter contravariant in input
position.
Details
Contravariant<A> is assignable to Contravariant<B> when B extends A,
following the supertype direction.
Example (Defining a contravariant phantom type)
import type { Types } from "effect"
interface Consumer<T> {
readonly _phantom: Types.Contravariant<T>
readonly accept: (value: T) => void
}
Namespace for
Contravariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Contravariant.
Contravariant<function (type parameter) E in Variance<in A, in E>E>
}
}
/**
* Namespace containing type definitions for TxDequeue variance annotations.
*
* @since 4.0.0
*/
export declare namespace TxDequeue {
/**
* Variance annotation interface for TxDequeue covariance.
*
* @category models
* @since 4.0.0
*/
export interface interface TxDequeue<out A, out E = never>.Variance<out A, out E>Variance annotation interface for TxDequeue covariance.
Variance<out function (type parameter) A in Variance<out A, out E>A, out function (type parameter) E in Variance<out A, out E>E> {
readonly TxDequeue<out A, out E = never>.Variance<out A, out E>._A: Types.Covariant<A>_A: import TypesTypes.type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) A in Variance<out A, out E>A>
readonly TxDequeue<out A, out E = never>.Variance<out A, out E>._E: Types.Covariant<E>_E: import TypesTypes.type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) E in Variance<out A, out E>E>
}
}
/**
* Namespace containing type definitions for TxQueue variance annotations.
*
* @since 4.0.0
*/
export declare namespace TxQueue {
/**
* Variance annotation interface for TxQueue invariance.
*
* @category models
* @since 4.0.0
*/
export interface interface TxQueue<in out A, in out E = never>.Variance<in out A, in out E>Variance annotation interface for TxQueue invariance.
Variance<in out function (type parameter) A in Variance<in out A, in out E>A, in out function (type parameter) E in Variance<in out A, in out E>E> {
readonly TxQueue<in out A, in out E = never>.Variance<in out A, in out E>._A: Types.Invariant<A>_A: import TypesTypes.type Invariant<A> = (_: A) => AFunction-type alias encoding invariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter invariant, neither
covariant nor contravariant.
Details
A value of type Invariant<A> cannot be assigned to Invariant<B> unless
A and B are the same type.
Example (Defining an invariant phantom type)
import type { Types } from "effect"
interface Container<T> {
readonly _phantom: Types.Invariant<T>
readonly value: T
}
Namespace for
Invariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Invariant.
Invariant<function (type parameter) A in Variance<in out A, in out E>A>
readonly TxQueue<in out A, in out E = never>.Variance<in out A, in out E>._E: Types.Invariant<E>_E: import TypesTypes.type Invariant<A> = (_: A) => AFunction-type alias encoding invariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter invariant, neither
covariant nor contravariant.
Details
A value of type Invariant<A> cannot be assigned to Invariant<B> unless
A and B are the same type.
Example (Defining an invariant phantom type)
import type { Types } from "effect"
interface Container<T> {
readonly _phantom: Types.Invariant<T>
readonly value: T
}
Namespace for
Invariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Invariant.
Invariant<function (type parameter) E in Variance<in out A, in out E>E>
}
}
/**
* Represents the shared state of a transactional queue that can be inspected.
* This interface contains the core properties needed for queue state inspection
* operations like size, capacity, and completion status.
*
* @category models
* @since 4.0.0
*/
export interface TxQueueState extends import InspectableInspectable {
readonly TxQueueState.strategy: "bounded" | "unbounded" | "dropping" | "sliding"strategy: "bounded" | "unbounded" | "dropping" | "sliding"
readonly TxQueueState.capacity: numbercapacity: number
readonly 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 TxChunkTxChunk.type TxChunk.TxChunk = /*unresolved*/ anyTxChunk<any>
readonly 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: import TxRefTxRef.interface TxRef<in out A>TxRef is a transactional value, it can be read and modified within the body of a transaction.
When to use
Use to store mutable state that must be read and modified inside Effect
transactions.
Details
Accessed values are tracked by the transaction in order to detect conflicts and in order to
track changes, a transaction will retry whenever a conflict is detected or whenever the
transaction explicitely calls to Effect.txRetry and any of the accessed TxRef values
change.
Example (Using a transactional reference)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
// Create a transactional reference
const ref: TxRef.TxRef<number> = yield* TxRef.make(0)
// Use within a transaction
yield* Effect.tx(Effect.gen(function*() {
const current = yield* TxRef.get(ref)
yield* TxRef.set(ref, current + 1)
}))
const final = yield* TxRef.get(ref)
console.log(final) // 1
})
TxRef<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<any, any>>
}
/**
* 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)
*
* ```ts
* 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)
* })
* ```
*
* @category models
* @since 4.0.0
*/
export interface 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<in function (type parameter) A in TxEnqueue<in A, in E = never>A, in function (type parameter) E in TxEnqueue<in A, in E = never>E = never> extends TxQueueState {
readonly [const EnqueueTypeId: "~effect/transactions/TxQueue/Enqueue"EnqueueTypeId]: TxEnqueue.interface TxEnqueue<in A, in E = never>.Variance<in A, in E>Variance annotation interface for TxEnqueue contravariance.
Variance<function (type parameter) A in TxEnqueue<in A, in E = never>A, function (type parameter) E in TxEnqueue<in A, in E = never>E>
}