Guest User

Untitled

a guest
Oct 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public CompletableFuture<Result> getFuture() {
  2. CompletableFuture<A> resultA = serviceA.call();
  3. CompletableFuture<B> resultB = resultA.thenCompose(a -> serviceB.call(a));
  4. CompletableFuture<C> resultC = resultA.thenCompose(a -> serviceC.call(a));
  5. return CompletableFuture.allOf(resultB, resultC)
  6. .thenApply(ignoredVoid -> combine(
  7. resultA.join(),
  8. resultB.getNow(fallbackB),
  9. resultC.getNow(fallbackC));
  10. }
  11.  
  12. public Result extractFuture(CompletableFuture<Result> future) {
  13. Result result;
  14. try {
  15. result = future.get(timeOut, MILLISECONDS);
  16. } catch (ExecutionException ex) {
  17. ...
  18. } catch (InterruptedException | TimeoutException ex) {
  19. // I always ends up here...
  20. }
  21. return result;
  22. }
Add Comment
Please, Sign In to add comment