<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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<type Option<A> = O.None<A> | O.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<type Result<A, E = never> = Res.Success<A, E> | Res.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<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<A, E>.ref: TxRef.TxRef<Option<Result<A, E>>>(property) TxDeferred<A, E>.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)