coderzc commented on code in PR #17164:
URL: https://github.com/apache/pulsar/pull/17164#discussion_r973101218


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/Futures.java:
##########
@@ -68,4 +69,28 @@ public static CompletableFuture<Void> 
waitForAll(List<CompletableFuture<Void>> f
 
         return compositeFuture;
     }
+
+    public static <T> CompletableFuture<T> 
executeWithRetry(Supplier<CompletableFuture<T>> op,
+                                                            Class<? extends 
Exception> needRetryExceptionClass) {
+        CompletableFuture<T> resultFuture = new CompletableFuture<>();
+        op.get().whenComplete((res, ex) -> {
+            if (ex == null) {
+                resultFuture.complete(res);
+            } else {
+                if (needRetryExceptionClass.isAssignableFrom(ex.getClass())) {
+                    executeWithRetry(op, 
needRetryExceptionClass).whenComplete((res2, ex2) -> {
+                        if (ex2 == null) {
+                            resultFuture.complete(res2);
+                        } else {
+                            resultFuture.completeExceptionally(ex2);
+                        }
+                    });
+                    return;
+                }
+                resultFuture.completeExceptionally(ex);
+            }
+        });
+
+        return resultFuture;
+    }

Review Comment:
   `RetryUtil#retryAsynchronously` can't retry based on a specific exception, I 
will improve it in another PR when.



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