Deferred represents an asynchronous variable that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling Deferred.await) and automatically resume when the variable is set.
Deferred can be used for building primitive actions whose completions require the coordinated action of multiple fibers, and for building higher-level concurrent or asynchronous structures.
Type
Deferred<A, E> can be completed with a value of type A or an error of type E.
Creating Deferred
make
Creates a newDeferred.
unsafeMake
Unsafely creates a newDeferred from a FiberId.
Awaiting Completion
await
Retrieves the value of theDeferred, suspending the fiber until the result is available.
poll
Returns aSome<Effect<A, E>> if the Deferred has already been completed, None otherwise.
isDone
Returnstrue if the Deferred has been completed, false otherwise.
Completing with Success
succeed
Completes theDeferred with a value.
true if the deferred was successfully completed, false if it was already completed.
complete
Completes the deferred with the result of an effect. The result is memoized.completeWith
Completes the deferred with the result of an effect, without memoizing.Completing with Failure
fail
Fails theDeferred with an error.
failCause
Fails theDeferred with a Cause.
die
Kills theDeferred with a defect.
Completing with Exit
done
Completes theDeferred with an Exit value.
Interruption
interrupt
Completes theDeferred with interruption.
interruptWith
Completes theDeferred with interruption from a specific fiber.