Created
May 18, 2018 08:34
-
-
Save elizarov/ed0f701d047013dc3fb5c6bec539a457 to your computer and use it in GitHub Desktop.
CompletableFuture exception wrapping
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
import java.util.concurrent.* | |
fun main(args: Array<String>) { | |
class DomainSpecificException : RuntimeException() | |
val cf1 = CompletableFuture<Int>() | |
val cf2 = CompletableFuture<Int>() | |
val res = cf1.thenCompose { cf2 } | |
cf1.whenComplete { _, err -> println("cf1: Completed with error = $err") } | |
cf2.whenComplete { _, err -> println("cf2: Completed with error = $err") } | |
res.whenComplete { _, err -> println("res: Completed with error = $err") } | |
cf2.completeExceptionally(DomainSpecificException()) | |
cf1.complete(239) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment