public static < T > CompletableFuture < Void > loop ( Iterable < T > iterable , Function < T , CompletableFuture < Boolean > > loopBody , Executor executor ) { Iterator < T > iterator = iterable . iterator ( ) ; AtomicBoolean canContinue = new AtomicBoolean ( true ) ; return loop ( ( ) -> iterator . hasNext ( ) && canContinue . get ( ) , ( ) -> loopBody . apply ( iterator . next ( ) ) , canContinue :: set , executor ) ; }
Executes a loop using CompletableFutures over the given Iterable processing each item in order without overlap using the given Executor for task execution .