Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public CompletableFuture<Result> getFuture() {
- CompletableFuture<A> resultA = serviceA.call();
- CompletableFuture<B> resultB = resultA.thenCompose(a -> serviceB.call(a));
- CompletableFuture<C> resultC = resultA.thenCompose(a -> serviceC.call(a));
- return CompletableFuture.allOf(resultB, resultC)
- .thenApply(ignoredVoid -> combine(
- resultA.join(),
- resultB.getNow(fallbackB),
- resultC.getNow(fallbackC));
- }
- public Result extractFuture(CompletableFuture<Result> future) {
- Result result;
- try {
- result = future.get(timeOut, MILLISECONDS);
- } catch (ExecutionException ex) {
- ...
- } catch (InterruptedException | TimeoutException ex) {
- // I always ends up here...
- }
- return result;
- }
Add Comment
Please, Sign In to add comment