keith-turner commented on code in PR #2752:
URL: https://github.com/apache/accumulo/pull/2752#discussion_r897416883
##########
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).
Review Comment:
Based on the little experiment I did, I don't think this is a potential
problem. In that experiment there were only two threads in the pool and it
iterated 5 times w/o problem.
--
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]