public final class FutureCompanion extends Object
Future
. import static javascalautils.FutureCompanion.Future; Future<Integer> resultSuccess = Future(() -> 9 / 3); // The Future will at some point contain: Success(3) Future<Integer> resultFailure = Future(() -> 9 / 0); // The Future will at some point contain: Failure(ArithmeticException)
Modifier and Type | Method and Description |
---|---|
static <T> Future<T> |
Future(Future<T> future)
Allows for converting a blocking JDK
Future into a non-blocking future. |
static <T> Future<T> |
Future(Future<T> future,
Executor executor)
Allows for converting a blocking JDK
Future into a non-blocking future. |
static <T> Future<T> |
Future(ThrowableFunction0<T> function)
Allows for easy creation of asynchronous computations that will be executed in the future.
|
static <T> Future<T> |
Future(ThrowableFunction0<T> function,
Executor executor)
Allows for easy creation of asynchronous computations that will be executed in the future.
|
public static <T> Future<T> Future(ThrowableFunction0<T> function)
Future.apply(ThrowableFunction0)
. import static javascalautils.concurrent.FutureCompanion.Future; Future<Integer> resultSuccess = Future(() -> 9 / 3); // The Future will at some point contain: Success(3) Future<Integer> resultFailure = Future(() -> 9 / 0); // The Future will at some point contain: Failure(ArithmeticException)
T
- The type for the Futurefunction
- The function to render either the value T or raise an exception.Future.apply(ThrowableFunction0)
public static <T> Future<T> Future(ThrowableFunction0<T> function, Executor executor)
Future.apply(ThrowableFunction0)
. import static javascalautils.concurrent.FutureCompanion.Future; Future<Integer> resultSuccess = Future(() -> 9 / 3, someExecutor); // The Future will at some point contain: Success(3) Future<Integer> resultFailure = Future(() -> 9 / 0, someExecutor); // The Future will at some point contain: Failure(ArithmeticException)
T
- The type for the Futurefunction
- The function to render either the value T or raise an exception.executor
- The executor to use to compute/execute the Future holding the provided functionFuture.apply(ThrowableFunction0, Executor)
public static <T> Future<T> Future(Future<T> future)
Future
into a non-blocking future. T
- The type for the Futurefuture
- The blocking futurepublic static <T> Future<T> Future(Future<T> future, Executor executor)
Future
into a non-blocking future.T
- The type for the Futurefuture
- The blocking futureexecutor
- The executor to use to compute/execute the Future holding the provided functionCopyright © 2015, Peter Nerg Apache License v2.0