Skip to content

Commit

Permalink
perf: use cffuCompleteOnTimeout instead of cffuOrTimeout in `most…
Browse files Browse the repository at this point in the history
…Of*` methods for single input cf ⚡️

`cffuCompleteOnTimeout` won't create `TimeoutException`
  • Loading branch information
oldratlee committed Jun 15, 2024
1 parent bf97d1c commit a9a18ff
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ public static <T> CompletableFuture<List<T>> mostResultsOfSuccess(
if (cfs.length == 0) return completedFuture(arrayList());
if (cfs.length == 1) {
// Defensive copy input cf to non-minimal-stage instance in order to
// 1. avoid writing it by `cffuOrTimeout` and is able to read its result(`getSuccessNow`)
// 1. avoid writing it by `cffuCompleteOnTimeout` and is able to read its result(`getSuccessNow`)
// 2. ensure that the returned cf is not minimal-stage CF instance(UnsupportedOperationException)
final CompletableFuture<T> f = toNonMinCfCopy(requireNonNull(cfs[0], "cf1 is null"));
return cffuOrTimeout(f, executorWhenTimeout, timeout, unit)
return cffuCompleteOnTimeout(f, valueIfNotSuccess, executorWhenTimeout, timeout, unit)
.handle((unused, ex) -> arrayList(getSuccessNow(f, valueIfNotSuccess)));
}

Expand Down

0 comments on commit a9a18ff

Please sign in to comment.