Skip to content

Commit

Permalink
perf(CFU): do NOT reuse incomplete CF instance in methods `bothFail…
Browse files Browse the repository at this point in the history
…Fast0/eitherSuccess0` like `fill0` 🤖

more info see issue:

#236 (comment)
  • Loading branch information
oldratlee committed Dec 22, 2024
1 parent bf38c0f commit 4977274
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 4977274

Please sign in to comment.