nodece commented on code in PR #15454:
URL: https://github.com/apache/pulsar/pull/15454#discussion_r867353802
##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -55,6 +57,36 @@ public static CompletableFuture<Object>
waitForAny(Collection<? extends Completa
return CompletableFuture.anyOf(futures.toArray(new
CompletableFuture[0]));
}
+ public static CompletableFuture<Optional<Object>> waitForAny(Collection<?
extends CompletableFuture<?>> futures,
+ Predicate<Object>
tester) {
+ return waitForAny(futures).thenCompose(v -> {
+ if (tester.test(v)) {
+ return CompletableFuture.completedFuture(Optional.of(v));
+ }
+ Collection<CompletableFuture<?>> doneFutures = futures.stream()
+ .filter(f -> f.isDone())
+ .collect(Collectors.toList());
+ futures.removeAll(doneFutures);
+ Optional<?> value = doneFutures.stream()
+ .filter(f -> !f.isCompletedExceptionally())
+ .map(CompletableFuture::join)
Review Comment:
Can we avoid the `join`? async & sync operation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]