Skip to content

Commit

Permalink
feat(imp):[#214] improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed Jan 18, 2024
1 parent 6a117dd commit 8137cd2
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public <T> CompletableFuture<T> getFastestResult(final List<CompletableFuture<T>

final List<Throwable> exceptions = new ArrayList<>();

final var handledFutures = //
toArray(futures.stream()
.map(future -> future.exceptionally(
completingExceptionallyCollectingException(exceptions))
.handle(completingOnFirstSuccessful(fastestResultPromise)))
.toList());
final var futuresList = futures.stream()
.map(future -> future.exceptionally(collectingExceptionsAndThrow(exceptions))
.handle(completingOnFirstSuccessful(fastestResultPromise)))
.toList();

allOf(handledFutures).whenComplete((value, ex) -> {
allOf(toArray(futuresList)).whenComplete((value, ex) -> {

log.debug("List of futures completed");

Expand Down Expand Up @@ -118,8 +116,7 @@ private static <T> BiFunction<T, Throwable, Boolean> completingOnFirstSuccessful
};
}

private static <T> Function<Throwable, T> completingExceptionallyCollectingException(
final List<Throwable> exceptions) {
private static <T> Function<Throwable, T> collectingExceptionsAndThrow(final List<Throwable> exceptions) {
return t -> {
log.error("Exception occurred: " + t.getMessage(), t);
exceptions.add(t);
Expand Down

0 comments on commit 8137cd2

Please sign in to comment.