Package: effect
Module: Deferred
Computes a defect when the returned effect is run, then attempts to complete
the Deferred with that defect.
When to use
Use to lazily compute an unexpected defect when the completion effect runs.
Details
Fibers waiting on the Deferred die with the computed defect only if this
call completes it. The returned effect succeeds with true when this call
completed the Deferred, or false if it was already completed.
Example (Killing a Deferred with a lazy defect)
import { Deferred, Effect } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* Deferred.make<number>()
const success = yield* Deferred.dieSync(
deferred,
() => new Error("Lazy error")
)
console.log(success) // true
})
Signature
declare const dieSync: { (evaluate: LazyArg<unknown>): <A, E>(self: Deferred<A, E>) => Effect<boolean>; <A, E>(self: Deferred<A, E>, evaluate: LazyArg<unknown>): Effect<boolean>; }
Since v2.0.0