Skip to content

Instantly share code, notes, and snippets.

@elizarov
Created May 18, 2018 08:34
Show Gist options
  • Save elizarov/ed0f701d047013dc3fb5c6bec539a457 to your computer and use it in GitHub Desktop.
Save elizarov/ed0f701d047013dc3fb5c6bec539a457 to your computer and use it in GitHub Desktop.
CompletableFuture exception wrapping
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