java.util.concurrent Helpers for joining Futures using Tuples
Possibly create a way to join and map CompletableFutures.
public static <T1, T2, T3> Tuple3<T1, T2, T3> joinAll(
CompletableFuture<T1> f1,
CompletableFuture<T2> f2,
CompletableFuture<T3> f3) {
// Do we even need this allOf since we join below anyway.
CompletableFuture.allOf(f1, f2, f3).join();
return Tuple.tuple(f1.join(), f2.join(), f3.join());
}
Could be combined like so.
return Futures.joinAll(emailFuture, tagFuture, rolesFuture).map(User::new);
Full example shown here https://gist.github.com/billoneil/f949def19560f379bec9aa640b19120c#file-gistfile1-java-L23
Thank you very much for your suggestion. That is an interesting approach. Should we decide to provide utilities for the JDK's concurrency APIs (see also https://github.com/jOOQ/jOOL/issues/283), this multi-join-into-tuple approach definitely makes sense.
@lukaseder any thoughts on this since we added the new CompletionStage? Ideally it would accept CompletionStages but they would need to be converted to CompletableFuture to call join() or CompletableFuture.allOf(
Thanks for pinging, @billoneil. I think this idea needs to ripe a bit, first. Improving this area seems to be scratching an itch that few people have, and at this stage, I'm very uncertain of what a good API would be. I currently don't want to rush adding this new API.
No problem totally agree. Just wanted to see if you had any thoughts. I might make something similar internally and see if I like it.