Skip to content

Commit

Permalink
Use new List#toArray method
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit committed Oct 3, 2023
1 parent 5220c26 commit 5bb65da
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.pivovarit.collectors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -79,14 +78,14 @@ public Set<Characteristics> characteristics() {
}

private static <T> CompletableFuture<Stream<T>> combine(List<CompletableFuture<T>> futures) {
CompletableFuture<T>[] futuresArray = (CompletableFuture<T>[]) futures.toArray(new CompletableFuture[0]);
CompletableFuture<Stream<T>> combined = allOf(futuresArray)
.thenApply(__ -> Arrays.stream(futuresArray).map(CompletableFuture::join));

for (CompletableFuture<?> f : futuresArray) {
f.exceptionally(ex -> {
combined.completeExceptionally(ex);
return null;
var combined = allOf(futures.toArray(CompletableFuture[]::new))
.thenApply(__ -> futures.stream().map(CompletableFuture::join));

for (var future : futures) {
future.whenComplete((o, ex) -> {
if (ex != null) {
combined.completeExceptionally(ex);
}
});
}

Expand Down

0 comments on commit 5bb65da

Please sign in to comment.