Created
May 11, 2018 00:00
-
-
Save vichu/7a585d79e2abd16fae9099c263600b26 to your computer and use it in GitHub Desktop.
Chaining thenApply method on CompletableFutures
This file contains 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
CompletableFuture<CompletableFuture<CompletableFuture<Map<String, Object>>>> result = myCompletableFutureBigDecimal.thenApply(bigDecimal -> | |
myCompletableFutureInt.thenApply( integer -> | |
myCompletableFutureLong.thenApply(aLong -> { | |
Map<String, Object> objectHashMap = new HashMap<>(); | |
objectHashMap.put("IntegerValue", integer); | |
objectHashMap.put("LongValue", aLong); | |
objectHashMap.put("BigDecimalValue", bigDecimal); | |
return objectHashMap; | |
}))); | |
try { | |
Map<String, Object> re = result | |
.get(2, TimeUnit.SECONDS) | |
.get() | |
.get(); | |
System.out.println(re); | |
} catch (InterruptedException | ExecutionException | TimeoutException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment