mcastiblanco
02/19/2018, 2:45 AMJob
doesn't have a Failed state like Deferred
? currently a Job that fails (e.g throws an unhandled exception) ends up in a Completed state. The only way to actually know if it was a failure is by checking the message of the CancellationException
. Here is an example:
fun main(args: Array<String>) = runBlocking {
val job = launch {
throw TODO("Not ready!")
}
// wait for it to crash
delay(200)
println("cancelled [${job.isCancelled}]") // -> false
println("active [${job.isActive}]") // -> false
println("completed [${job.isCompleted}]") // -> true
}