TxDeferred
Transactional deferred values for coordinating Effect transactions.
A TxDeferred<A, E> is a write-once cell whose completion is a Result<A, E> stored in transactional state. Readers can wait for the value from inside a transaction: while the cell is empty the transaction retries, and when another transaction completes the deferred the waiting transaction can resume with either the success value or the typed failure.
Constructors
Getters
Reads the deferred value. Retries the transaction if the deferred has not been completed yet.
Signature
declare function await<A, E>(self: TxDeferred<A, E>): Effect<A, E>;Reads the current state of the deferred without retrying. Returns None if not yet completed.
When to use
Use to inspect a TxDeferred without retrying when it is not completed yet.
Signature
declare function poll<A, E>(self: TxDeferred<A, E>): Effect<Option<Result<A, E>>>;Guards
isTxDeferred
Determines if the provided value is a TxDeferred.
When to use
Use to narrow an unknown value before treating it as a transactional deferred.
Signature
declare function isTxDeferred(u: unknown): u is TxDeferred<unknown, unknown>;Models
TxDeferred interface
A transactional deferred is a write-once cell readable within transactions. Readers block (retry the transaction) until a value is committed, and writers succeed only on the first call; subsequent writes return false.
When to use
Use to coordinate transaction-local readers and one-time completion with a success or failure result.
Signature
interface TxDeferred<in out A, in out E = never> extends Inspectable, Pipeable {
readonly "~effect/transactions/TxDeferred": "~effect/transactions/TxDeferred";
readonly ref: TxRef<Option<Result<A, E>>>;
}Mutations
Completes the deferred with a Result. Returns true if this was the first completion, false if already completed.
When to use
Use to complete a TxDeferred with an already computed Result.
Signature
declare const done: {
<A, E>(result: Result<A, E>): (self: TxDeferred<A, E>) => Effect<boolean>;
<A, E>(self: TxDeferred<A, E>, result: Result<A, E>): Effect<boolean>;
};Completes the deferred with a failure. Returns true if this was the first completion, false if already completed.
When to use
Use to complete a TxDeferred with a typed failure value.
Signature
declare const fail: {
<E>(error: E): <A>(self: TxDeferred<A, E>) => Effect<boolean>;
<A, E>(self: TxDeferred<A, E>, error: E): Effect<boolean>;
};Completes the deferred with a success value. Returns true if this was the first completion, false if already completed.
When to use
Use to complete a TxDeferred with a successful value.
Signature
declare const succeed: {
<A>(value: A): <E>(self: TxDeferred<A, E>) => Effect<boolean>;
<A, E>(self: TxDeferred<A, E>, value: A): Effect<boolean>;
};
Creates a new empty
TxDeferred.When to use
Use to create a transactional deferred that can be completed exactly once.