SHARE
TWEET

Untitled

a guest Mar 21st, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public CompletableFuture<Boolean> doA();
  2. public CompletableFuture<Boolean> doB();
  3.      
  4. return doA() || doB();
  5.      
  6. doA.thenApply(b -> {
  7.   if (!b) {
  8.     return doB();
  9.   } else {
  10.     return CompletableFuture.completedFuture(b);
  11.   }
  12. }
  13.      
  14. CompletableFuture<Boolean> result = doA().thenCompose(b -> b
  15.     ? CompletableFuture.completedFuture(Boolean.TRUE) : doB());
  16.      
  17. static <T> CompletableFuture<T> flatten(
  18.   CompletableFuture<CompletableFuture<T>> nestedFuture) {
  19.     return nestedFuture.thenCompose(Function.identity());
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top