CompletableFuture chaining results

前端 未结 2 1287
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 07:17

I am trying to chain the calls/results of the methods to the next call. I get compile time error methodE because if am not able to get the reference of objB from the previou

2条回答
  •  感动是毒
    2021-01-12 08:03

    You could store intermediate CompletableFuture in a variable and then use thenCombine:

    CompletableFuture futureA = CompletableFuture.supplyAsync(...)
        .thenApply(...)
        .thenApply(...);
    
    CompletableFuture futureB = futureA.thenApply(...);
    
    CompletableFuture futureC = futureA.thenCombine(futureB, service::methodE);
    
    objC = futureC.join();
    

提交回复
热议问题