I am trying to associate method calls / results with the next call. I get a compile-time error method because if I fail to get the objB link to the previous call.
How to pass the result of the previous call to the next chain? Have I completely misunderstood this process?
Object objC = CompletableFuture.supplyAsync(() -> service.methodA(obj, width, height)) .thenApply(objA -> { try { return service.methodB(objA); } catch (Exception e) { throw new CompletionException(e); } }) .thenApply(objA -> service.methodC(objA)) .thenApply(objA -> { try { return service.methodD(objA); // this returns new objB how do I get it and pass to next chaining call } catch (Exception e) { throw new CompletionException(e); } }) .thenApply((objA, objB) -> { return service.methodE(objA, objB); // compilation error }) .get();
source share