I want to implement a hybrid of CompletableFuture.allOf() and CompletableFuture.anyOf() where the returned future completes successfully as soon as
This question is actually very similar to Replace Futures.successfulAsList with Java 8 CompletableFuture?
Although the question is not exactly the same, the same answer (from myself) should satisfy your needs.
You can implement this with a combination of allOf() and chaining each input future with an exceptionally() that would make the future returned by allOf() immediately fail:
CompletableFuture a = …, b = …, c = …;
CompletableFuture allWithFailFast = CompletableFuture.allOf(a, b, c);
Stream.of(a, b, c)
.forEach(f -> f.exceptionally(e -> {
allWithFailFast.completeExceptionally(e);
return null;
}));