public class FutureKt
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.concurrent.CompletableFuture<T> |
asCompletableFuture(kotlinx.coroutines.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> kotlinx.coroutines.Deferred<T> |
asDeferred(java.util.concurrent.CompletionStage<T> $receiver)
|
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.util.concurrent.CompletableFuture<T> |
future(kotlinx.coroutines.CoroutineScope $receiver,
NonExistentClass context,
kotlinx.coroutines.CoroutineStart start,
kotlin.jvm.functions.Function2<? super kotlinx.coroutines.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.
The running coroutine is cancelled when the resulting future is cancelled or otherwise completed.
|
public static <T> java.util.concurrent.CompletableFuture<T> future(kotlinx.coroutines.CoroutineScope $receiver,
NonExistentClass context,
kotlinx.coroutines.CoroutineStart start,
kotlin.jvm.functions.Function2<? super kotlinx.coroutines.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. The running coroutine is cancelled when the resulting future is cancelled or otherwise completed.
Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding coroutineContext element.
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 - additional to CoroutineScope.coroutineContext context of the coroutine.start - coroutine start option. The default value is CoroutineStart.DEFAULT.block - the coroutine code.public static <T> java.util.concurrent.CompletableFuture<T> asCompletableFuture(kotlinx.coroutines.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> kotlinx.coroutines.Deferred<T> asDeferred(java.util.concurrent.CompletionStage<T> $receiver)
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 cancellable.
If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function
stops waiting for the completion stage and immediately resumes with CancellationException.
This method is intended to be used with one-shot futures, so on coroutine cancellation completion stage is cancelled as well if it is instance of CompletableFuture.
If cancelling given stage is undesired, stage.asDeferred().await() should be used instead.