eolivelli commented on code in PR #19258:
URL: https://github.com/apache/pulsar/pull/19258#discussion_r1072233224


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -258,4 +259,25 @@ public static CompletionException 
wrapToCompletionException(Throwable throwable)
             return new CompletionException(throwable);
         }
     }
+
+    /**
+     * Creates a new {@link CompletableFuture} instance catching

Review Comment:
   The return type is "void"
   Maybe we can reword this like:
   
   "Executes an operation using the supplied Executor and notify failures on 
the supplied CompletableFuture"



##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java:
##########
@@ -258,4 +259,25 @@ public static CompletionException 
wrapToCompletionException(Throwable throwable)
             return new CompletionException(throwable);
         }
     }
+
+    /**
+     * Creates a new {@link CompletableFuture} instance catching
+     * potential exceptions and completing the future exceptionally.
+     *
+     * @param runnable the runnable to execute
+     * @param executor  the executor to use for executing the runnable
+     * @param completableFuture  the future to complete in case of exceptions
+     * @return
+     */
+
+    public static void safeRunAsync(Runnable runnable,
+                                    Executor executor,
+                                    CompletableFuture completableFuture) {
+        CompletableFuture
+                .runAsync(runnable, executor)
+                .exceptionally((throwable) -> {
+                    completableFuture.completeExceptionally(throwable);

Review Comment:
   should we complete the Future on the same Executor ?
   do we provide any guarantees on the thread that completes exceptionally the 
Future ?



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