Starting with Java 8, there is now the class CompletableFuture<T> , which supports continuation and more functional / reactive programming approaches.
Consider the following example where the class offers the downloadAndResize method:
public CompletableFuture<Image> downloadAndResize(String imageUrl, int width, int height) { return CompletableFuture .supplyAsync(() -> downloadImage(imageUrl)) .thenApplyAsync(x -> resizeImage(x, width, height)); } private Image downloadImage(String url){
Using the above method might look like this:
CompletableFuture<Image> imagePromise = downloadAndResize("http://some/url", 300, 200); imagePromise.thenAccept(image -> {
IsNull May 9 '15 at 9:19 AM 2015-05-09 09:19
source share