public class FutureKt
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.concurrent.CompletableFuture<T> |
asCompletableFuture(kotlinx.coroutines.experimental.Deferred<? extends T> $receiver)
Converts this deferred value to the instance of CompletableFuture.
The deferred value is cancelled when the resulting future is cancelled or otherwise completed.
|
static <T> java.lang.Object |
await(java.util.concurrent.CompletionStage<T> $receiver,
kotlin.coroutines.experimental.Continuation<? super T> p)
Awaits for completion of the completion stage without blocking a thread.
|
static <T> java.lang.Object |
await(java.util.concurrent.CompletableFuture<T> $receiver,
kotlin.coroutines.experimental.Continuation<? super T> p)
Awaits for completion of the future without blocking a thread.
|
static <T> java.util.concurrent.CompletableFuture<T> |
future(kotlin.coroutines.experimental.CoroutineContext context,
kotlinx.coroutines.experimental.CoroutineStart start,
kotlinx.coroutines.experimental.Job parent,
kotlin.jvm.functions.Function2<? super kotlinx.coroutines.experimental.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super T>,? extends java.lang.Object> block)
Starts new coroutine and returns its result as an implementation of CompletableFuture.
This coroutine builder uses CommonPool context by default and is conceptually similar to CompletableFuture.supplyAsync.
|
public static <T> java.util.concurrent.CompletableFuture<T> future(kotlin.coroutines.experimental.CoroutineContext context,
kotlinx.coroutines.experimental.CoroutineStart start,
kotlinx.coroutines.experimental.Job parent,
kotlin.jvm.functions.Function2<? super kotlinx.coroutines.experimental.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super T>,? extends java.lang.Object> block)
Starts new coroutine and returns its result as an implementation of CompletableFuture. This coroutine builder uses CommonPool context by default and is conceptually similar to CompletableFuture.supplyAsync.
The running coroutine is cancelled when the resulting future is cancelled or otherwise completed.
The context for the new coroutine can be explicitly specified.
See CoroutineDispatcher for the standard context implementations that are provided by kotlinx.coroutines.
The context of the parent coroutine from its scope may be used,
in which case the Job of the resulting coroutine is a child of the job of the parent coroutine.
The parent job may be also explicitly specified using parent parameter.
If the context does not have any dispatcher nor any other ContinuationInterceptor, then DefaultDispatcher is used.
By default, the coroutine is immediately scheduled for execution.
Other options can be specified via start parameter. See CoroutineStart for details.
A value of CoroutineStart.LAZY is not supported
(since CompletableFuture framework does not provide the corresponding capability) and
produces IllegalArgumentException.
See newCoroutineContext for a description of debugging facilities that are available for newly created coroutine.
context - context of the coroutine. The default value is DefaultDispatcher.start - coroutine start option. The default value is CoroutineStart.DEFAULT.parent - explicitly specifies the parent job, overrides job from the context (if any).block - the coroutine code.public static <T> java.util.concurrent.CompletableFuture<T> asCompletableFuture(kotlinx.coroutines.experimental.Deferred<? extends T> $receiver)
Converts this deferred value to the instance of CompletableFuture. The deferred value is cancelled when the resulting future is cancelled or otherwise completed.
public static <T> java.lang.Object await(java.util.concurrent.CompletionStage<T> $receiver,
kotlin.coroutines.experimental.Continuation<? super T> p)
Awaits for completion of the completion stage without blocking a thread.
This suspending function is not cancellable, because there is no way to cancel a CompletionStage.
Use CompletableFuture.await() for cancellable wait.
public static <T> java.lang.Object await(java.util.concurrent.CompletableFuture<T> $receiver,
kotlin.coroutines.experimental.Continuation<? super T> p)
Awaits for completion of the future without blocking a thread.
This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the future and immediately resumes with CancellationException.
Note, that CompletableFuture does not support prompt removal of installed listeners, so on cancellation of this wait
a few small objects will remain in the CompletableFuture stack of completion actions until the future completes.
However, the care is taken to clear the reference to the waiting coroutine itself, so that its memory can be
released even if the future never completes.