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 d35a6b405b2b4..51c6087558ab8 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,6 +20,7 @@ import java.time.Duration; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -37,6 +38,19 @@ */ public class FutureUtil { + /** + * Return a future that represents the completion of the futures in the provided List. + * This method with the List parameter is needed to keep compatibility with external + * applications that are compiled with Pulsar < 2.10.0. + * + * @param futures futures to wait for + * @return a new CompletableFuture that is completed when all of the given CompletableFutures complete + */ + @Deprecated + public static CompletableFuture waitForAll(List> futures) { + return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); + } + /** * Return a future that represents the completion of the futures in the provided Collection. * @@ -47,6 +61,19 @@ public static CompletableFuture waitForAll(Collection waitForAny(List> futures) { + return CompletableFuture.anyOf(futures.toArray(new CompletableFuture[0])); + } + /** * Return a future that represents the completion of any future in the provided Collection. *