public static class Deferred.DefaultImpls
Deferred value is a non-blocking cancellable future — it is a interface Job that has a result.
It is created with BuildersKt.async coroutine builder or via constructor of interface CompletableDeferred class.
It is in Job.isActive state while the value is being computed.
Deferred value has the same state machine as the interface Job with additional convenience methods to retrieve
successful or failed result of the computation that was carried out. The result of the deferred is
available when it is Job.isCompleted and can be retrieved by Deferred.await method, which throws
exception if the deferred had failed.
Note, that a cancelled deferred is also considered to be completed.
The corresponding exception can be retrieved via Deferred.getCompletionExceptionOrNull from a completed instance of deferred.
Usually, a deferred value is created in active state (it is created and started).
However, BuildersKt.async coroutine builder has an optional start parameter that creates a deferred value in new state
when this parameter is set to CoroutineStart.LAZY.
Such a deferred can be be made active by invoking Job.start, Job.join, or Deferred.await.
A deferred value is a interface Job. A job in the
coroutineContext
of BuildersKt.async builder represents the coroutine itself.
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.
| Modifier and Type | Method and Description |
|---|---|
static <T,R> R |
fold(Deferred<? extends T> $this,
R initial,
kotlin.jvm.functions.Function2<? super R,? super kotlin.coroutines.experimental.CoroutineContext.Element,? extends R> operation) |
static <T,E extends Element> |
get(Deferred<? extends T> $this,
kotlin.coroutines.experimental.CoroutineContext.Key<E> key) |
static <T> java.lang.Throwable |
getCompletionException(Deferred<? extends T> $this)
Deprecated.
|
static <T> kotlin.coroutines.experimental.CoroutineContext |
minusKey(Deferred<? extends T> $this,
kotlin.coroutines.experimental.CoroutineContext.Key<?> key) |
static <T> Job |
plus(Deferred<? extends T> $this,
Job other)
Deprecated.
|
static <T> kotlin.coroutines.experimental.CoroutineContext |
plus(Deferred<? extends T> $this,
kotlin.coroutines.experimental.CoroutineContext context) |
public static <T> java.lang.Throwable getCompletionException(Deferred<? extends T> $this)
public static <T> kotlin.coroutines.experimental.CoroutineContext plus(Deferred<? extends T> $this, kotlin.coroutines.experimental.CoroutineContext context)
public static <T,R> R fold(Deferred<? extends T> $this, R initial, kotlin.jvm.functions.Function2<? super R,? super kotlin.coroutines.experimental.CoroutineContext.Element,? extends R> operation)
public static <T,E extends Element> E get(Deferred<? extends T> $this, kotlin.coroutines.experimental.CoroutineContext.Key<E> key)
public static <T> kotlin.coroutines.experimental.CoroutineContext minusKey(Deferred<? extends T> $this, kotlin.coroutines.experimental.CoroutineContext.Key<?> key)