CompletableDeferred

interface CompletableDeferred<T> : Deferred<T>

A Deferred that can be completed via public functions complete or cancel.

Note that the complete function returns false when this deferred value is already complete or completing, while cancel returns true as long as the deferred is still cancelling and the corresponding exception is incorporated into the final completion exception.

An instance of completable deferred can be created by CompletableDeferred() function in active state.

All functions on this interface are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

The CompletableDeferred interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

Functions

complete
Link copied to clipboard
abstract fun complete(value: T): Boolean

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).

completeExceptionally
Link copied to clipboard
abstract fun completeExceptionally(exception: Throwable): Boolean

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).

Extensions

completeWith
Link copied to clipboard
fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean

Completes this deferred value with the value or exception in the given result. Returns true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

Sources

common source
Link copied to clipboard