Skip to content

Instantly share code, notes, and snippets.

@chrisphelps
Created January 2, 2016 18:56
Show Gist options
  • Save chrisphelps/c7051ceddea09b0f45b0 to your computer and use it in GitHub Desktop.
Save chrisphelps/c7051ceddea09b0f45b0 to your computer and use it in GitHub Desktop.
Use of a helper function to hide the nested transform
public ListenableFuture<List<Item>> getUserItemsWithConfig(User user, ListenableFuture<Config> configFuture) {
// transform on configFuture and call getItems(user, config)
...
}
public List<Item> getItems(User user, Config config) { ... }
ListenableFuture<User> user = getUser(args);
final ListenableFuture<Config> config = getConfig(args);
ListenableFuture<List<Item>> items = Futures.transform(user,
new AsyncFunction<User, List<Item>>() {
public ListenableFuture<List<Item>> apply(User user) throws Exception {
return getUserItemsWithConfig(user, config);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment