Ejemplo n.º 1
0
 /**
  * Allows for converting a blocking JDK {@link java.util.concurrent.Future Future} into a
  * non-blocking future.
  *
  * @param <T> The type for the Future
  * @param future The blocking future
  * @param executor The executor to use to compute/execute the Future holding the provided function
  * @return The future that will hold the result provided by the future
  * @since 1.5
  */
 public static <T> Future<T> Future(java.util.concurrent.Future<T> future, Executor executor) {
   return Future.apply(() -> future.get(), executor);
 }
Ejemplo n.º 2
0
 /**
  * Allows for easy creation of asynchronous computations that will be executed in the future. <br>
  * The method relays the execution to {@link Future#apply(ThrowableFunction0)}. <br>
  * Best used in conjunction with statically importing this method.
  *
  * <blockquote>
  *
  * <pre>
  * import static javascalautils.concurrent.FutureCompanion.Future;
  *
  * Future&lt;Integer&gt; resultSuccess = Future(() -&gt; 9 / 3, someExecutor); // The Future will at some point contain: Success(3)
  * Future&lt;Integer&gt; resultFailure = Future(() -&gt; 9 / 0, someExecutor); // The Future will at some point contain: Failure(ArithmeticException)
  * </pre>
  *
  * </blockquote>
  *
  * @param <T> The type for the Future
  * @param function The function to render either the value <i>T</i> or raise an exception.
  * @param executor The executor to use to compute/execute the Future holding the provided function
  * @return The future that will hold the result provided by the function
  * @since 1.4
  * @see Future#apply(ThrowableFunction0, Executor)
  */
 public static <T> Future<T> Future(ThrowableFunction0<T> function, Executor executor) {
   return Future.apply(function, executor);
 }
Ejemplo n.º 3
0
 /**
  * Allows for converting a blocking JDK {@link java.util.concurrent.Future Future} into a
  * non-blocking future. <br>
  * This will use the default executor to wait/block on the provided future.
  *
  * @param <T> The type for the Future
  * @param future The blocking future
  * @return The future that will hold the result provided by the future
  * @since 1.5
  */
 public static <T> Future<T> Future(java.util.concurrent.Future<T> future) {
   return Future.apply(() -> future.get());
 }
Ejemplo n.º 4
0
 /**
  * Allows for easy creation of asynchronous computations that will be executed in the future. <br>
  * The method relays the execution to {@link Future#apply(ThrowableFunction0)}. <br>
  * Best used in conjunction with statically importing this method.
  *
  * <blockquote>
  *
  * <pre>
  * import static javascalautils.concurrent.FutureCompanion.Future;
  *
  * Future&lt;Integer&gt; resultSuccess = Future(() -&gt; 9 / 3); // The Future will at some point contain: Success(3)
  * Future&lt;Integer&gt; resultFailure = Future(() -&gt; 9 / 0); // The Future will at some point contain: Failure(ArithmeticException)
  * </pre>
  *
  * </blockquote>
  *
  * @param <T> The type for the Future
  * @param function The function to render either the value <i>T</i> or raise an exception.
  * @return The future that will hold the result provided by the function
  * @since 1.3
  * @see Future#apply(ThrowableFunction0)
  */
 public static <T> Future<T> Future(ThrowableFunction0<T> function) {
   return Future.apply(function);
 }