Deferred, a powerful concurrency primitive that represents an asynchronous variable that can be set exactly once. Multiple fibers can await the same Deferred and will all be notified when it completes.
Overview
ADeferred<A, E> is like a promise that can be:
- Completed successfully with a value of type
A - Failed with an error of type
E - Interrupted if the fiber setting it is interrupted
- Single assignment: Can only be completed once
- Multiple waiters: Many fibers can await the same
Deferred - Fiber-safe: Thread-safe operations across concurrent fibers
- Composable: Works seamlessly with other Effect operations
Basic Usage
Types
Deferred
Creating Deferreds
make
Deferred.
makeUnsafe
Deferred without Effect wrapping.
Awaiting Values
await
Deferred, suspending the fiber until the result is available.
Completing Deferreds
succeed
Deferred with the specified value. Returns false if already completed.
sync
Deferred with a lazily evaluated value.
complete
completeWith
Failing Deferreds
fail
Deferred with the specified error.
failSync
Deferred with a lazily evaluated error.
failCause
Deferred with the specified Cause.
failCauseSync
Deferred with a lazily evaluated Cause.
Killing Deferreds
die
Deferred with the specified defect.
dieSync
Deferred with a lazily evaluated defect.
Interrupting Deferreds
interrupt
Deferred with interruption. This will interrupt all fibers waiting on the value.
interruptWith
Deferred with interruption using the specified FiberId.
Completion Status
done
Deferred with the specified Exit value.
isDone
true if the Deferred has already been completed.
isDoneUnsafe
Deferred has been completed.
poll
Deferred has already been completed, undefined otherwise.
Unsafe Operations
doneUnsafe
Deferred with the specified effect.
Integration with Effects
into
Effect into an operation that completes a Deferred with its result.
