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) //code that performs a side effect but has not return type can be written like this Future<Unit> f = Future(() -> { database.delete(someId); });
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.
|
static Future<Unit> |
Future(VoidFunction0 function)
Allows for easy creation of asynchronous computations that will be executed in the future.
|
static Future<Unit> |
Future(VoidFunction0 function,
Executor executor)
Allows for easy creation of asynchronous computations that will be executed in the future.
|
public static Future<Unit> Future(VoidFunction0 function)
Success
/Failure
. Future.apply(ThrowableFunction0)
. import static javascalautils.concurrent.FutureCompanion.Future; Future<Unit> t = Future(() -> { database.delete(someId); });
function
- The function to render either the value T or raise an exception.Unit
or an exception.Future.apply(ThrowableFunction0)
public static Future<Unit> Future(VoidFunction0 function, Executor executor)
Success
/Failure
. Future.apply(ThrowableFunction0)
. import static javascalautils.concurrent.FutureCompanion.Future; Future<Unit> t = Future(() -> { database.delete(someId); }, someExecutor);
function
- 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 functionUnit
or an exception.Future.apply(ThrowableFunction0)
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 © 2016, Peter Nerg Apache License v2.0