I have a future that would ideally take two parameters coming from two other futures. For this I have .thenCombine(), the trick here is that the second future needs the result of the first one.
Let's say:
- I have futures A, B and C
- Future B needs the result of future A
- Future C needs the result of future A and B
I would like to have something like:
CompletableFuture<Customer> customerFuture = CompletableFuture.supplyAsync(() -> findCustomer(123));
CompletableFuture<Shop> shopFuture = CompletableFuture.supplyAsync((customer) ->getAllAccessibleShops(customer));
CompletableFuture<Route> routeFuture = customerFuture.thenCombine(shopFuture, (cust, shop) -> findRoute(cust, shop));
Of course thenCombine() is not what I'm looking for and the code above looks dumb because I shouldn't need the customer afterwards, but this is only an example.
Is there a way to achieve this?