July 2018
Intermediate to advanced
266 pages
7h 11m
English
Unlike a pure job, deferred will not propagate unhandled exceptions automatically. It's done this way because it's expected that you will wait for the result of deferred, so it's up to you to validate that the execution was successful. Here's an example where deferred is not awaited:
fun main(args: Array<String>) = runBlocking { val deferred = async { TODO("Not implemented yet!") } // Wait for it to fail delay(2000)}
The preceding example will have deferred fail, but it will not propagate the exception. Here, we are using delay() so that we can reproduce an scenario in which we are not monitoring the execution of deferred—which you should never do—because deferred is intended to be monitored. Let's see how we can get the ...
Read now
Unlock full access