public class FutureConverters$
extends java.lang.Object
Note that the bridge is implemented at the read-only side of asynchronous
handles, namely scala.concurrent.Future instead of scala.concurrent.Promise
and CompletionStage instead of CompletableFuture. This is intentional, as
the semantics of bridging the write-handles would be prone to race
conditions; if both ends (CompletableFuture and Promise) are completed
independently at the same time, they may contain different values afterwards.
For this reason, toCompletableFuture()
is not supported on the
created CompletionStages.
Example usage:
import java.util.concurrent.CompletionStage;
import scala.concurrent.Future;
import static scala.concurrent.java8.FutureConverter.*;
final CompletionStage<String> cs = ... // from an async Java API
final Future<String> f = toScala(cs);
...
final Future<Integer> f2 = ... // from an async Scala API
final CompletionStage<Integer> cs2 = toJava(f2);
Modifier and Type | Field and Description |
---|---|
static FutureConverters$ |
MODULE$
Static reference to the singleton instance of this Scala object.
|
Constructor and Description |
---|
FutureConverters$() |
Modifier and Type | Method and Description |
---|---|
<T> FutureConverters.CompletionStageOps<T> |
CompletionStageOps(java.util.concurrent.CompletionStage<T> cs) |
<T> scala.concurrent.Promise<T> |
failedPromise(java.lang.Throwable ex)
Construct an already fulfilled
scala.concurrent.Promise which holds the given failure. |
scala.concurrent.ExecutionContextExecutor |
fromExecutor(java.util.concurrent.Executor e)
Creates an ExecutionContext from a given Executor, using the
default reporter for uncaught exceptions which will just call
.printStackTrace() . |
scala.concurrent.ExecutionContextExecutor |
fromExecutor(java.util.concurrent.Executor e,
java.util.function.Consumer<java.lang.Throwable> reporter)
Creates an ExecutionContext from a given Executor, using the given
Consumer for reporting errors.
|
scala.concurrent.ExecutionContextExecutorService |
fromExecutorService(java.util.concurrent.ExecutorService e)
Creates an ExecutionContext from a given ExecutorService, using the
default reporter for uncaught exceptions which will just call
.printStackTrace() . |
scala.concurrent.ExecutionContextExecutorService |
fromExecutorService(java.util.concurrent.ExecutorService e,
java.util.function.Consumer<java.lang.Throwable> reporter)
Creates an ExecutionContext from a given ExecutorService, using the given
Consumer for reporting errors.
|
<T> FutureConverters.FutureOps<T> |
FutureOps(scala.concurrent.Future<T> f) |
scala.concurrent.ExecutionContext |
globalExecutionContext()
Return the global ExecutionContext for Scala Futures.
|
<T> scala.concurrent.Promise<T> |
keptPromise(T v)
Construct an already fulfilled
scala.concurrent.Promise which holds the given value. |
<T> scala.concurrent.Promise<T> |
promise()
Construct an empty
scala.concurrent.Promise . |
<T> java.util.concurrent.CompletionStage<T> |
toJava(scala.concurrent.Future<T> f)
Returns a CompletionStage that will be completed with the same value or
exception as the given Scala Future when that completes.
|
<T> scala.concurrent.Future<T> |
toScala(java.util.concurrent.CompletionStage<T> cs)
Returns a Scala Future that will be completed with the same value or
exception as the given CompletionStage when that completes.
|
public static final FutureConverters$ MODULE$
public <T> java.util.concurrent.CompletionStage<T> toJava(scala.concurrent.Future<T> f)
toCompletableFuture
method. The semantics of Scala Future
demand that all callbacks are invoked asynchronously by default, therefore
the returned CompletionStage routes all calls to synchronous
transformations to their asynchronous counterparts, i.e.
thenRun
will internally call thenRunAsync
.
f
- The Scala Future which may eventually supply the completion for
the returned CompletionStagepublic <T> scala.concurrent.Future<T> toScala(java.util.concurrent.CompletionStage<T> cs)
cs
- The CompletionStage which may eventually supply the completion
for the returned Scala Futurepublic scala.concurrent.ExecutionContextExecutorService fromExecutorService(java.util.concurrent.ExecutorService e, java.util.function.Consumer<java.lang.Throwable> reporter)
final ExecutionContext ec = Converter.fromExecutorService(es, thr -> thr.printStackTrace());
e
- an ExecutorServicereporter
- a Consumer for reporting errors during executionpublic scala.concurrent.ExecutionContextExecutorService fromExecutorService(java.util.concurrent.ExecutorService e)
.printStackTrace()
.
e
- an ExecutorServicepublic scala.concurrent.ExecutionContextExecutor fromExecutor(java.util.concurrent.Executor e, java.util.function.Consumer<java.lang.Throwable> reporter)
final ExecutionContext ec = Converter.fromExecutor(es, thr -> thr.printStackTrace());
e
- an Executorreporter
- a Consumer for reporting errors during executionpublic scala.concurrent.ExecutionContextExecutor fromExecutor(java.util.concurrent.Executor e)
.printStackTrace()
.
e
- an Executorpublic scala.concurrent.ExecutionContext globalExecutionContext()
public <T> scala.concurrent.Promise<T> promise()
scala.concurrent.Promise
.
public <T> scala.concurrent.Promise<T> keptPromise(T v)
scala.concurrent.Promise
which holds the given value.
v
- (undocumented)public <T> scala.concurrent.Promise<T> failedPromise(java.lang.Throwable ex)
scala.concurrent.Promise
which holds the given failure.
ex
- (undocumented)public <T> FutureConverters.FutureOps<T> FutureOps(scala.concurrent.Future<T> f)
public <T> FutureConverters.CompletionStageOps<T> CompletionStageOps(java.util.concurrent.CompletionStage<T> cs)