Java Thread Future sequence(List> futures)

Here you can find the source of sequence(List> futures)

Description

sequence

License

Apache License

Declaration

public static <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public class Main {
    public static <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures) {
        /*/*from  www  .  j  av  a2 s  . c om*/
            CompletableFuture<Void> allDoneFuture =
        CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
            return allDoneFuture.thenApply(v ->
        futures.stream().
                map(future -> future.join()).
                collect(Collectors.<T>toList())
            );
        */
        return CompletableFuture
                .supplyAsync(() -> futures.stream().map(future -> future.join()).collect(Collectors.<T>toList()));
    }
}

Related

  1. now(Collection> s)
  2. rollback(Object tx)
  3. runIfNotDoneAndGet(RunnableFuture future)
  4. runInNewThread(String threadName, Runnable target)
  5. sequence(List> futures)
  6. sequence(List> futures)
  7. sequence(List> futures)
  8. submitTasks(ExecutorCompletionService ecs, Iterable> tasks)
  9. sumFutures(List> futures)