Last active
December 17, 2015 02:48
-
-
Save mgodave/5538189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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