merlimat closed pull request #3270: Relay on CompletableFuture utils
URL: https://github.com/apache/pulsar/pull/3270
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java
b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java
index e07941a56d..0aa6a96a7b 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java
@@ -20,8 +20,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
public class FutureUtil {
@@ -31,32 +29,8 @@
* @param futures
* @return
*/
- public static <T> CompletableFuture<T>
waitForAll(List<CompletableFuture<T>> futures) {
- if (futures.isEmpty()) {
- return CompletableFuture.completedFuture(null);
- }
-
- final CompletableFuture<T> compositeFuture = new CompletableFuture<>();
- final AtomicInteger count = new AtomicInteger(futures.size());
- final AtomicReference<Throwable> exception = new AtomicReference<>();
-
- for (CompletableFuture<T> future : futures) {
- future.whenComplete((r, ex) -> {
- if (ex != null) {
- exception.compareAndSet(null, ex);
- }
- if (count.decrementAndGet() == 0) {
- // All the pending futures did complete
- if (exception.get() != null) {
- compositeFuture.completeExceptionally(exception.get());
- } else {
- compositeFuture.complete(null);
- }
- }
- });
- }
-
- return compositeFuture;
+ public static <T> CompletableFuture<Void>
waitForAll(List<CompletableFuture<T>> futures) {
+ return CompletableFuture.allOf(futures.toArray(new
CompletableFuture[0]));
}
public static <T> CompletableFuture<T> failedFuture(Throwable t) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services