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
common
abstract fun complete(value: T): Boolean
Completes this deferred value with a given value.
completeExceptionally
Link copied to clipboard
common
abstract fun completeExceptionally(exception: Throwable): Boolean
Completes this deferred value exceptionally with a given exception.

Extensions

completeWith
Link copied to clipboard
common
fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean
Completes this deferred value with the value or exception in the given result.

Sources

common source
Link copied to clipboard