Skip to content

Commit 094417a

Browse files
committed
docs(CFU): improve comments
1 parent 1425787 commit 094417a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

.idea/dictionaries/cffu_project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cffu-core/src/main/java/io/foldright/cffu2/CompletableFutureUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,16 @@ static <T> CompletableFuture<List<T>> mostSuccessResultsOf0(
514514
CompletionStage<? extends T>[] cfs) {
515515
if (cfs.length == 0) return completedFuture(arrayList());
516516
if (cfs.length == 1) {
517-
// defensive copy input cf to non-minimal-stage instance in order to
517+
// copy input cf to non-minimal-stage instance in order to
518518
// 1. avoid writing it by `cffuCompleteOnTimeout` and is able to read its result(`getSuccessNow`)
519519
// 2. ensure that the returned cf is not a minimal-stage instance (UnsupportedOperationException)
520520
final CompletableFuture<T> f = toNonMinCfCopy0(cfs[0]);
521521
return cffuCompleteOnTimeout(f, valueIfNotSuccess, timeout, unit, executorWhenTimeout)
522522
.handle((unused, ex) -> arrayList(getSuccessNow(f, valueIfNotSuccess)));
523523
}
524524

525-
// 1. MUST be non-minimal-stage CF instances to read results(`getSuccessNow`), otherwise UnsupportedOpException.
526-
// 2. SHOULD copy input cfs (by calling `exceptionally` method) to avoid memory leaks,
527-
// otherwise all input cfs would be retained until output cf completes.
525+
// create new non-minimal-stage instances from input cfs by `toNonMinCf0`/`exceptionally`,
526+
// so results are readable by `getSuccessNow` instead of throwing UnsupportedOpException.
528527
CompletableFuture<T>[] cfArray = mapArray(cfs, CommonUtils::newCfArray,
529528
s -> LLCF.<T>toNonMinCf0(s).exceptionally(v -> valueIfNotSuccess));
530529
return cffuCompleteOnTimeout(CompletableFuture.allOf(cfArray), null, timeout, unit, executorWhenTimeout)
@@ -756,12 +755,12 @@ static <T> CompletableFuture<T> anySuccessOf0(CompletionStage<? extends T>[] cfs
756755
// 2. the returned cf is not a minimal-stage instance (UnsupportedOperationException)
757756
if (len == 1) return toNonMinCfCopy0(cfs[0]);
758757

759-
// NOTE: fill ONE MORE element of successOrBeIncompleteCfs LATER
758+
// NOTE: fill ONE MORE element of successOrBeIncomplete LATER
760759
final CompletableFuture<?>[] successOrBeIncomplete = newCfArray(len + 1);
761760
final CompletableFuture<Void>[] failedOrBeIncomplete = newCfArray(len);
762761
fill0(cfs, successOrBeIncomplete, failedOrBeIncomplete);
763762

764-
// NOTE: fill the ONE MORE element of successOrBeIncompleteCfs HERE:
763+
// NOTE: fill the ONE MORE element of successOrBeIncomplete HERE:
765764
// a cf that is completed exceptionally when all given cfs completed exceptionally, otherwise be incomplete
766765
successOrBeIncomplete[len] = CompletableFuture.allOf(failedOrBeIncomplete);
767766

0 commit comments

Comments
 (0)