Java tutorial
//package com.java2s; import java.util.List; import java.util.concurrent.CompletableFuture; public class Main { public static <T> CompletableFuture<T> anyOfFutures(List<? extends CompletableFuture<? extends T>> futures) { CompletableFuture<T> cf = new CompletableFuture<>(); CompletableFuture .allOf(futures.stream().map(f -> f.thenAccept(cf::complete)).toArray(CompletableFuture<?>[]::new)) .exceptionally(ex -> { cf.completeExceptionally(ex); return null; }); return cf; } }