/* package whatever; // don't place package name! */
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.LockSupport;
import java.util.function.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
CompletableFuture.supplyAsync(()->{ LockSupport.parkNanos(10_000_000_000L); return "hello"; })))
.join();
}
public static <T>
CompletableFuture<T> anyOf(List<? extends CompletionStage<? extends T>> l) {
CompletableFuture<T> f=new CompletableFuture<>();
Consumer<T> complete=f::complete;
CompletableFuture.allOf(
l.stream().map(s -> s.thenAccept(complete)).toArray(CompletableFuture<?>[]::new)
).exceptionally(ex -> { f.completeExceptionally(ex); return null; });
return f;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLmNvbmN1cnJlbnQuKjsKaW1wb3J0IGphdmEudXRpbC5jb25jdXJyZW50LmxvY2tzLkxvY2tTdXBwb3J0OwppbXBvcnQgamF2YS51dGlsLmZ1bmN0aW9uLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewogICAgICAgIFN0cmluZyBzPWFueU9mKEFycmF5cy5hc0xpc3QoCiAgICAgICAgICAgIENvbXBsZXRhYmxlRnV0dXJlLnN1cHBseUFzeW5jKCgpLT57dGhyb3cgbmV3IFJ1bnRpbWVFeGNlcHRpb24oKTt9KSwKICAgICAgICAgICAgQ29tcGxldGFibGVGdXR1cmUuc3VwcGx5QXN5bmMoKCktPnsgTG9ja1N1cHBvcnQucGFya05hbm9zKDEwXzAwMF8wMDBfMDAwTCk7IHJldHVybiAia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