<A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<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.
Example (Polling a deferred)
import { Effect, Option, Result, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
const before = yield* TxDeferred.poll(deferred)
console.log(Option.isNone(before)) // true
yield* TxDeferred.succeed(deferred, 42)
const after = yield* TxDeferred.poll(deferred)
console.log(after) // Some(Success(42))
})export const const poll: <A, E>(
self: TxDeferred<A, E>
) => Effect.Effect<Option<Result<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.
Example (Polling a deferred)
import { Effect, Option, Result, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
const before = yield* TxDeferred.poll(deferred)
console.log(Option.isNone(before)) // true
yield* TxDeferred.succeed(deferred, 42)
const after = yield* TxDeferred.poll(deferred)
console.log(after) // Some(Success(42))
})
poll = <function (type parameter) A in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>E>(self: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
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; <…;
}
self: interface TxDeferred<in out A, in out E = never>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.
Example (Completing a transactional deferred)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
// Complete the deferred
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
// Second write is a no-op
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
// Read the value
const value = yield* TxDeferred.await(deferred)
console.log(value) // 42
})
TxDeferred<function (type parameter) A in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>E>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption<import ResultResult<function (type parameter) A in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>): Effect.Effect<Option<Result<A, E>>>E>>> => 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: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
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; <…;
}
self.TxDeferred<in out A, in out E = never>.ref: TxRef.TxRef<Option<Result<A, E>>>(property) TxDeferred<in out A, in out E = never>.ref: {
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; <…;
}
ref)