Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.util.concurrent Helpers for joining Futures using Tuples #282

Open
billoneil opened this issue Feb 11, 2017 · 4 comments
Open

java.util.concurrent Helpers for joining Futures using Tuples #282

billoneil opened this issue Feb 11, 2017 · 4 comments

Comments

@billoneil
Copy link
Contributor

billoneil commented Feb 11, 2017

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

@lukaseder
Copy link
Member

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 #283), this multi-join-into-tuple approach definitely makes sense.

@billoneil
Copy link
Contributor Author

@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(

@lukaseder
Copy link
Member

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.

@lukaseder lukaseder modified the milestones: On Hold, Version 0.9.13 May 8, 2017
@billoneil
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants