Java 类io.vertx.core.impl.CompositeFutureImpl 实例源码

项目:moviediary    文件:FutureUtils.java   
public static <T> Future<List<T>> reduce(List<Future<T>> futures) {
  return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()]))
                            .map(v -> futures.stream()
                                             .map(Future::result)
                                             .collect(Collectors.toList()));
}
项目:vertx-blueprint-microservice    文件:Functional.java   
/**
 * Evaluate a list of futures. Transforms a `List[Future[R]]` into a `Future[List[R]]`.
 * <p>
 * When all futures succeed, the result future completes with the list of each result of elements in {@code futures}.
 * </p>
 * The returned future fails as soon as one of the futures in {@code futures} fails.
 * When the list is empty, the returned future will be already completed.
 * <p>
 * Useful for reducing many futures into a single @{link Future}.
 *
 * @param futures a list of {@link Future futures}
 * @return the transformed future
 */
public static <R> Future<List<R>> allOfFutures(List<Future<R>> futures) {
  return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()]))
    .map(v -> futures.stream()
      .map(Future::result)
      .collect(Collectors.toList())
    );
}
项目:vertx-jspare    文件:FutureSupplier.java   
/**
 * Sequence with a list of futures. Transforms a `List[Future[R]]` into a
 * `Future[List[R]]`.
 * <p>
 * When all futures succeed, the result future completes with the list of each
 * result of elements in {@code futures}.
 * </p>
 * The returned future fails as soon as one of the futures in {@code futures}
 * fails. When the list is empty, the returned future will be already
 * completed.
 * <p>
 * Useful for reducing many futures into a single @{link Future}.
 *
 * @param futures a list of {@link Future futures}
 * @param <R>     the type R
 * @return the future
 */
public static <R> Future<List<R>> sequenceFuture(List<Future<R>> futures) {
  return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()]))
    .map(v -> futures.stream().map(Future::result).collect(Collectors.toList()));
}