Last active
November 14, 2018 16:20
-
-
Save valdo404/d1cba5a14d35bd002434e20b064695b4 to your computer and use it in GitHub Desktop.
Plain futures
This file contains hidden or 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
import com.google.common.util.concurrent.FutureCallback; | |
import com.google.common.util.concurrent.Futures; | |
import com.google.common.util.concurrent.ListenableFuture; | |
import javax.annotation.Nullable; | |
import java.util.concurrent.ExecutionException; | |
public class FuturesApp { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
ListenableFuture<Integer> future = Futures.immediateFuture(1); | |
Futures.addCallback(future, new FutureCallback<Integer>() { | |
@Override | |
public void onSuccess(@Nullable Integer result) { | |
System.out.println("woohoo" + result); | |
} | |
@Override | |
public void onFailure(Throwable t) { | |
System.out.println("woohoo" + t); | |
} | |
}); | |
System.out.println(future.get()); | |
} | |
} | |
public class CompletableFutureApp { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<Void> future = CompletableFuture.completedFuture(1) | |
.thenAccept(System.out::println); | |
future.get(); | |
} | |
} | |
public class ReactorApp { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
Flux<Integer> future = Flux.just(1, 2) | |
.flatMap(i -> Flux.just(i * 2, i* 3)) | |
.doOnEach(System.out::println); | |
future.collectList().toFuture().get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment