Skip to content

Commit

Permalink
refactor: rename local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 14, 2023
1 parent b983873 commit 294d4f4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/io/foldright/cffu/CompletableFutureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ public static <T> CompletableFuture<List<T>> allOfWithResult(CompletableFuture<T

final Object[] result = new Object[size];

final CompletableFuture<?>[] thenCfs = new CompletableFuture[size];
final CompletableFuture<?>[] collectResultCfs = new CompletableFuture[size];
for (int i = 0; i < size; i++) {
final int index = i;
final CompletableFuture<T> cf = cfs[index];

CompletableFuture<Void> thenCf = cf.thenAccept(x -> result[index] = x);
thenCfs[index] = thenCf;
collectResultCfs[index] = cfs[index].thenAccept(v -> result[index] = v);
}

return CompletableFuture.allOf(thenCfs)
return CompletableFuture.allOf(collectResultCfs)
.thenApply(unused -> (List<T>) Arrays.asList(result));
}

Expand Down Expand Up @@ -405,7 +402,7 @@ static <U> CompletableFuture<U> copy(CompletableFuture<U> cf) {
final CompletableFuture<Integer> cf = CompletableFuture.completedFuture(42);
try {
// `exceptionallyCompose` is the new method of CompletableFuture since java 12
cf.exceptionallyCompose(x -> cf);
cf.exceptionallyCompose(v -> cf);
b = true;
} catch (NoSuchMethodError e) {
b = false;
Expand Down

0 comments on commit 294d4f4

Please sign in to comment.