Skip to content

Commit

Permalink
perf: do NOT reuse incomplete CF instance in methods `bothFailFast0…
Browse files Browse the repository at this point in the history
…/eitherSuccess0` like`CompletableFutureUtils#fill0` 🤖

more see issue:

#236 (comment)
  • Loading branch information
oldratlee committed Dec 19, 2024
1 parent c39837b commit 61d80b6
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2466,14 +2466,12 @@ private static void requireThisAndOtherNonNull(CompletionStage<?> cfThis, Comple
@SuppressWarnings({"unchecked", "rawtypes"})
private static <T1, T2> CompletableFuture<Tuple2<T1, T2>> bothFailFast0(
CompletableFuture<? extends T1> cfThis, CompletionStage<? extends T2> other) {
final CompletableFuture incomplete = new CompletableFuture();

CompletableFuture thisSuccessOrBeIncomplete = exceptionallyCompose(cfThis, ex -> incomplete);
CompletionStage otherSuccessOrBeIncomplete = exceptionallyCompose(other, ex -> incomplete);
CompletableFuture thisSuccessOrBeIncomplete = exceptionallyCompose(cfThis, ex -> new CompletableFuture());
CompletionStage otherSuccessOrBeIncomplete = exceptionallyCompose(other, ex -> new CompletableFuture());
CompletableFuture cfValue = thisSuccessOrBeIncomplete.thenCombine(otherSuccessOrBeIncomplete, Tuple2::of);

CompletableFuture thisFailedOrBeIncomplete = cfThis.thenCompose(v -> incomplete);
CompletionStage otherFailedOrBeIncomplete = other.thenCompose(v -> incomplete);
CompletableFuture thisFailedOrBeIncomplete = cfThis.thenCompose(v -> new CompletableFuture());
CompletionStage otherFailedOrBeIncomplete = other.thenCompose(v -> new CompletableFuture());
CompletableFuture cfEx = thisFailedOrBeIncomplete.applyToEither(otherFailedOrBeIncomplete, v -> null);

return cfValue.applyToEither(cfEx, x -> x);
Expand Down Expand Up @@ -2644,14 +2642,12 @@ public static <T, U> CompletableFuture<U> applyToEitherSuccessAsync(
@SuppressWarnings({"unchecked", "rawtypes"})
private static <T> CompletableFuture<T> eitherSuccess0(
CompletableFuture<? extends T> cfThis, CompletionStage<? extends T> other) {
final CompletableFuture incomplete = new CompletableFuture();

CompletableFuture thisSuccessOrBeIncomplete = exceptionallyCompose(cfThis, ex -> incomplete);
CompletionStage otherSuccessOrBeIncomplete = exceptionallyCompose(other, ex -> incomplete);
CompletableFuture thisSuccessOrBeIncomplete = exceptionallyCompose(cfThis, ex -> new CompletableFuture());
CompletionStage otherSuccessOrBeIncomplete = exceptionallyCompose(other, ex -> new CompletableFuture());
CompletableFuture cfValue = thisSuccessOrBeIncomplete.applyToEither(otherSuccessOrBeIncomplete, x -> x);

CompletableFuture thisFailedOrBeIncomplete = cfThis.thenCompose(v -> incomplete);
CompletionStage otherFailedOrBeIncomplete = other.thenCompose(v -> incomplete);
CompletableFuture thisFailedOrBeIncomplete = cfThis.thenCompose(v -> new CompletableFuture());
CompletionStage otherFailedOrBeIncomplete = other.thenCompose(v -> new CompletableFuture());
CompletableFuture cfEx = thisFailedOrBeIncomplete.thenCombine(otherFailedOrBeIncomplete, (v1, v2) -> null);

return cfValue.applyToEither(cfEx, x -> x);
Expand Down

0 comments on commit 61d80b6

Please sign in to comment.