dlmarion commented on code in PR #2752:
URL: https://github.com/apache/accumulo/pull/2752#discussion_r894431301


##########
core/src/main/java/org/apache/accumulo/core/util/CompletableFutureUtil.java:
##########
@@ -49,4 +51,28 @@ public static <T> CompletableFuture<T> 
merge(List<CompletableFuture<T>> futures,
     return futures.get(0);
   }
 
+  /**
+   * Asynchronously, iterate some function until a given condition is met.
+   */
+  public static <T> CompletableFuture<T> 
iterateWhileAsync(Function<T,CompletableFuture<T>> step,
+      Predicate<T> isDone, T init) {
+    // We'd like to use a lambda here, but lambdas don't have
+    // `this`, so we would have to use some clumsy indirection to
+    // achieve self-reference.
+    Function<T,CompletableFuture<T>> go = new Function<>() {
+      @Override
+      public CompletableFuture<T> apply(T x) {
+        if (isDone.test(x)) {
+          return CompletableFuture.completedFuture(x);
+        }
+        // Making the recursive call with thenComposeAsync prevents
+        // stack overflows (but risks deadlock if we run out of
+        // threads).
+        //
+        // TODO should this method take an ExecutorService argument?

Review Comment:
   I think the answer to this question is `yes`. I'm not familiar with these 
objects, but from what I understand they will use the common ForkJoin pool. I'm 
not sure what happens when a failure happens in this pool while running a task. 
We have instrumented our `Threads` and `ThreadPools` class to take specific 
actions when tasks throw unhandled `Exception` and `Error`.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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

Reply via email to