chia7712 commented on code in PR #15462:
URL: https://github.com/apache/kafka/pull/15462#discussion_r1516205356


##########
server-common/src/main/java/org/apache/kafka/server/util/FutureUtils.java:
##########
@@ -125,4 +127,21 @@ public static <T> CompletableFuture<T> combineFutures(
             return res;
         });
     }
+
+    /**
+     * Applies the given exception handler to all the futures provided in the 
list
+     * and returns a new list of futures.
+     *
+     * @param futures   A list of futures.
+     * @param fn        A function taking an exception to handle it.
+     * @return A list of futures.
+     */
+    public static <T> List<CompletableFuture<T>> mapExceptionally(

Review Comment:
   This functionality is good idea. Maybe we can merge this it into 
`combineFutures` to make `combineFutures` to generate array with exception 
handler. For example:
   ```java
     public static <T> CompletableFuture<T> combineFutures(
         List<CompletableFuture<T>> futures,
         Supplier<T> init,
         BiConsumer<T, T> add
     ) {
       return combineFutures(futures, init, add, null);
     }
   
     public static <T> CompletableFuture<T> combineFutures(
         List<CompletableFuture<T>> futures,
         Supplier<T> init,
         BiConsumer<T, T> add,
         Function<Throwable, ? extends T> fn
     ) {
       final CompletableFuture<Void> allFutures = fn == null ? 
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
         : CompletableFuture.allOf(futures.stream().map(f -> 
f.exceptionally(fn)).toArray(CompletableFuture[]::new));
       return allFutures.thenApply(v -> {
         final T res = init.get();
         futures.forEach(future -> add.accept(res, future.join()));
         return res;
       });
     }
   ```
   
   The benefit is that we save a collection re-creation, and also 
`combineFutures` gets more functionality with acceptable complex ( 4 parameters 
)
   
   



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to