Skip to content

Commit ceb5200

Browse files
committed
fix: correct failfast behavior
Closes #426
1 parent ec522d0 commit ceb5200

File tree

1 file changed

+18
-9
lines changed
  • c2me-opts-allocs/src/main/java/com/ishland/c2me/opts/allocs/mixin

1 file changed

+18
-9
lines changed

c2me-opts-allocs/src/main/java/com/ishland/c2me/opts/allocs/mixin/MixinUtil.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.List;
99
import java.util.concurrent.CompletableFuture;
10+
import java.util.function.BiConsumer;
1011
import java.util.stream.Collectors;
1112

1213
@Mixin(Util.class)
@@ -28,10 +29,14 @@ public static <V> CompletableFuture<List<V>> combineSafe(List<CompletableFuture<
2829
@Overwrite
2930
public static <V> CompletableFuture<List<V>> combine(List<CompletableFuture<V>> futures) {
3031
final CompletableFuture<List<V>> future = Combinators.collect(futures, Collectors.toList()).toCompletableFuture();
31-
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).exceptionally(e -> {
32-
future.completeExceptionally(e);
33-
return null;
34-
});
32+
BiConsumer<V, Throwable> action = (v, throwable) -> {
33+
if (throwable != null) {
34+
future.completeExceptionally(throwable);
35+
}
36+
};
37+
for (CompletableFuture<V> completableFuture : futures) {
38+
completableFuture.whenComplete(action);
39+
}
3540
return future;
3641
}
3742

@@ -42,11 +47,15 @@ public static <V> CompletableFuture<List<V>> combine(List<CompletableFuture<V>>
4247
@Overwrite
4348
public static <V> CompletableFuture<List<V>> combineCancellable(List<CompletableFuture<V>> futures) {
4449
final CompletableFuture<List<V>> future = Combinators.collect(futures, Collectors.toList()).toCompletableFuture();
45-
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).exceptionally(e -> {
46-
future.completeExceptionally(e);
47-
futures.forEach(f -> f.cancel(false));
48-
return null;
49-
});
50+
BiConsumer<V, Throwable> action = (v, throwable) -> {
51+
if (throwable != null) {
52+
future.completeExceptionally(throwable);
53+
futures.forEach(f -> f.cancel(false));
54+
}
55+
};
56+
for (CompletableFuture<V> completableFuture : futures) {
57+
completableFuture.whenComplete(action);
58+
}
5059
return future;
5160
}
5261

0 commit comments

Comments
 (0)