public CompletableDeferred<T> extends Deferred<T>
A interface Deferred that can be completed via public functions
complete, completeExceptionally, and cancel.
Completion functions return false when this deferred value is already complete.
A completable deferred value has the following states:
| State | isActive | isCompleted | isCompletedExceptionally | isCancelled |
| ------------------------- | ---------- | ------------- | -------------------------- | ------------- |
| Active (initial state) | true | false | false | false |
| Cancelled (final state) | false | true | true | true |
| Resolved (final state) | false | true | false | false |
| Failed (final state) | false | true | true | false |
A an instance of completable deferred can be created by CompletableDeferred() function in active state.
+--------+ complete +-----------+
| Active | ---------+-> | Resolved |
+--------+ | |(completed)|
| | +-----------+
| cancel |
V | +-----------+
+-----------+ +-> | Failed |
| Cancelled | |(completed)|
|(completed)| +-----------+
+-----------+
All functions on this interface and on all interfaces derived from it are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.
interface DeferredDeferred.DefaultImpls| Modifier and Type | Method and Description |
|---|---|
boolean |
complete(T value)
Completes this deferred value with a given value. The result is
true if this deferred was
completed as a result of this invocation and false otherwise (if it was already completed). |
boolean |
completeExceptionally(java.lang.Throwable exception)
Completes this deferred value exceptionally with a given exception. The result is
true if this deferred was
completed as a result of this invocation and false otherwise (if it was already completed). |
await, getCompleted, getCompletionExceptionOrNull, getOnAwait, isCompletedExceptionallyattachChild, cancel, cancelChildren, getCancellationException, getOnJoin, invokeOnCompletion, isActive, isCancelled, isCompleted, join, startboolean complete(T value)
Completes this deferred value with a given value. The result is true if this deferred was
completed as a result of this invocation and false otherwise (if it was already completed).
Repeated invocations of this function have no effect and always produce false.
boolean completeExceptionally(java.lang.Throwable exception)
Completes this deferred value exceptionally with a given exception. The result is true if this deferred was
completed as a result of this invocation and false otherwise (if it was already completed).
Repeated invocations of this function have no effect and always produce false.