简体   繁体   中英

Intermediate executions on CompletableFutures List

I have a list of completableFutures where each future has varying time of execution(50-300ms).

//CompletableFuture[] futures
CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures);
allFutures.whenComplete(){
//Do Something
}

I want to add an intermediate step where after x ms, where I want to do some partial processing on completed futures, and combine results later

//CompletableFuture[] futures
SCHEDULER.schedule(() -> {
for(Future f: futures){
//Do Something else
}
}, 100, TimeUnit.MILLISECONDS);

CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures);
allFutures.whenComplete(){
//Do Something
}

Above doesn't look pretty to me, is there a better way of doing this, does Completable future have something out of the box for this?

Can be achieved through:

CompletableFutures DelayedExecutor 

or using Guava Libraries:

FluentFuture.withTimeout() conversion.

Both should be given an executor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM