Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
    }
}