MIDI
09/21/2026, 11:28 AMRobert Jaros
09/21/2026, 11:33 AMMIDI
09/21/2026, 11:35 AMCLOVIS
09/21/2026, 12:24 PMrunBlocking is not parallel by default, so "wrapping the entire application in `runBlocking`" doesn't improve performanceCLOVIS
09/21/2026, 12:28 PMI did not take this literally enough the first time I read it, but it truly is just “a thing”. To put it differently, aYeah. I like to describeis a tool you can use to describe and manage anything that fits this description.Job
Job as a remote control. You have a button to cancel it, a button to wait for it, etc, but the Job itself isn't the work.MIDI
09/21/2026, 12:32 PMCLOVIS
09/21/2026, 12:49 PMJob . When .cancel() is called, the Job is marked is marked cancelled and the Coroutines mechanisms know the coroutine is cancelled, without any exceptions.
The problem is: what happens to existing code? It is possible to just stop scheduling the coroutine, and so it blips out of existence right where it was.
coroutineScope {
val a = launch {
…
delay(100)
…
}
a.cancel()
}
Here, the coroutine would just disappear and never execute any more code.
The problem is if the user wrote:
coroutineScope {
val a = launch {
val file = File("…").open()
try {
delay(100)
} finally {
file.close()
}
…
}
a.cancel()
}
If the coroutine just disappeared, the finally {} block would never be executed, .close() would never run, and there would be a resource leak. Not good!
So anytime a coroutine gets killed (whether it's cancellation, or an error in a child coroutine, or anything else), the Coroutines library already knows that but will still throw an exception in the coroutine just to be sure that finally blocks are executed (and potentially other try…catch).CLOVIS
09/21/2026, 12:52 PMtry…finally complicates many parts of the Kotlin language. This is one example, there are a few others.CLOVIS
09/21/2026, 12:53 PMCancellationException , the parent still knows that the child has been cancelled: the exception isn't used to pass the message around, it's only used to give it a chance to the coroutine to orderly shut itself down.CLOVIS
09/21/2026, 1:04 PMCLOVIS
09/21/2026, 1:04 PMMIDI
09/21/2026, 1:07 PMOliver.O
09/23/2026, 11:15 AMMIDI
09/24/2026, 7:20 AM