<E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>
<A, E>(self: TxDeferred<A, E>, error: E): Effect.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.
Example (Completing with a failure)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number, string>()
const first = yield* TxDeferred.fail(deferred, "boom")
console.log(first) // true
const second = yield* TxDeferred.fail(deferred, "boom2")
console.log(second) // false
})export const const fail: {
<E>(error: E): <A>(
self: TxDeferred<A, E>
) => Effect.Effect<boolean>
<A, E>(
self: TxDeferred<A, E>,
error: E
): Effect.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.
Example (Completing with a failure)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number, string>()
const first = yield* TxDeferred.fail(deferred, "boom")
console.log(first) // true
const second = yield* TxDeferred.fail(deferred, "boom2")
console.log(second) // false
})
fail: {
<function (type parameter) E in <E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>E>(error: Eerror: function (type parameter) E in <E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>E): <function (type parameter) A in <A>(self: TxDeferred<A, E>): Effect.Effect<boolean>A>(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>(self: TxDeferred<A, E>): Effect.Effect<boolean>A, function (type parameter) E in <E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
<function (type parameter) A in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>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>, error: E): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>E>, error: Eerror: function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>E): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
} = import dualdual(
2,
<function (type parameter) A in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>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>, error: E): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>E>, error: Eerror: function (type parameter) E in <A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean>E): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean> => const done: {
<A, E>(result: Result<A, E>): (
self: TxDeferred<A, E>
) => Effect.Effect<boolean>
<A, E>(
self: TxDeferred<A, E>,
result: Result<A, E>
): Effect.Effect<boolean>
}
done(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, import ResRes.fail(error: Eerror))
)