lhotari commented on code in PR #17524:
URL: https://github.com/apache/pulsar/pull/17524#discussion_r1448552789


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -69,6 +70,35 @@ public static <T> CompletableFuture<List<T>> 
waitForAll(Stream<CompletableFuture
                 })));
     }
 
+    /**
+     * Make the dest future complete after another one. {@param dest} is will 
be completed with the same value as
+     * {@param src}, or be completed with the same error as {@param src}.
+     */
+    public static <T> void completeAfter(final CompletableFuture<T> dest, 
CompletableFuture<T> src){
+        src.whenComplete((v, ex) -> {
+            if (ex != null){
+                dest.completeExceptionally(ex);
+            } else {
+                dest.complete(v);
+            }
+        });
+    }
+
+    /**
+     * Make the dest future complete after others. {@param dest} is will be 
completed with the same value as
+     * {@param src} if all the futures of {@param src} is completed, or be 
completed exceptionally with the same error
+     * as the first one completed exceptionally future of {@param src}.
+     */
+    public static <T> void completeAfterAll(final CompletableFuture<Void> 
dest, CompletableFuture<T>...src){
+        FutureUtil.waitForAll(Arrays.asList(src)).whenComplete((ignore, ex) -> 
{
+            if (ex != null){
+                dest.completeExceptionally(ex);
+            } else {
+                dest.complete(null);
+            }
+        });
+    }

Review Comment:
   please reformat the code to fix some whitespace formatting issues



-- 
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]

Reply via email to