-
Notifications
You must be signed in to change notification settings - Fork 11k
Feature request: add support for transforming a tuple of futures into a single future #1421
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
Comments
Original comment posted by [email protected] on 2013-05-22 at 03:09 PM Though we've stayed away from Function2 and friends (<https://code.google.com/p/guava-libraries/wiki/IdeaGraveyard#Functions/Predicates_for_n_%3E=_2_inputs>), we can find other ways of merging Futures: final ListenableFuture<A> future1; In fact, we have this method internally. It may yet make its way out. |
Original comment posted by kristofer.karlsson on 2013-05-22 at 03:19 PM Thanks for quick response. final ListenableFuture<A> future1; so you wouldn't actually need to expose your combine. You could also do this, but I'm not sure it's any prettier: |
Original comment posted by [email protected] on 2013-05-22 at 03:27 PM Yep, allAsList+transform is pretty much how ours is implemented. (As it turns out, ours (a) uses successfulAsList so that you can choose to handle exceptions manually (or just let them propagate) and (b) uses the AsyncFunction version of transform() so that the Function can throw any kind of Exception (important in part because we make you call get() but also sometimes convenient for other reasons.) Part of what keeps us from going to tuple route is that, if we're going to address complex graphs of Futures, we probably want to go even further than an added method or two. There's at least one popular system available internally at Google, so we're kind of spoiled. |
Original comment posted by pettermahlen on 2014-01-31 at 09:24 AM We've created a framework that aims to simplify the problem of working with non-trivial asynchronous call graphs: https://github.com/spotify/trickle. It may be of interest until the day when the Google-internal system is made available to the public. |
We may still develop these further by integrating allAsList/successfulAsList into them. Related Guava request: #1421 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=110712191
Let's call this the bug for de- |
This is now fixed. |
While I did say...
...I think I had written that under the assumption that we wouldn't be de- |
Original issue created by kristofer.karlsson on 2013-05-22 at 03:01 PM
Sometimes it would be useful to combine the result of multiple futures into a single result, basically transforming a set of futures into a single future.
This is already supported to some extent through Futures.allAsList, but that only works if all futures are of the same type. I would want something similar, but that works on tuples instead of lists.
Something like this:
ListenableFuture<A> future1;
ListenableFuture<B> future1;
Function2<X, A, B> function = new Function2<X, A, B>(){
@Override
public X apply(A first, B second) {
return merge(first, second);
}
};
ListenableFuture<X> result = Futures.transform(future1, future2, function);
Attached is some sort of minimal implementation of this concept.
The text was updated successfully, but these errors were encountered: