Skip to content

Instantly share code, notes, and snippets.

@mgodave
Last active December 17, 2015 02:48
Show Gist options
  • Save mgodave/5538189 to your computer and use it in GitHub Desktop.
Save mgodave/5538189 to your computer and use it in GitHub Desktop.
public class ChainingExample {
private final Executor mainPool;
private final Executor ioPool;
public ChainingExample(Executor mainPool, Executor ioPool) {
this.mainPool = mainPool;
this.ioPool = ioPool;
}
public ListenableFuture<File> getMergedFileForUser(String user) throws Exception {
ListenableFuture<List<String>> files = getFilesForUser("dave");
ListenableFuture<List<URL>> urls =
Futures.transform(files, locateFiles(), mainPool);
ListenableFuture<List<File>> downloadedFiles =
Futures.transform(urls, downloadFiles(), mainPool);
return Futures.transform(downloadedFiles, mergeFiles(), ioPool);
}
ListenableFuture<List<String>> getFilesForUser(String user) { ... }
AsyncFunction<List<String>, List<URL>> locateFiles() { ... }
AsyncFunction<List<URL>, List<File>> downloadFiles() { ... }
AsyncFunction<List<File>, File> mergeFiles() { ... }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment