giso
03/11/2019, 4:14 PMAllan Wang
03/11/2019, 4:15 PMgiso
03/11/2019, 4:21 PMsuspend fun doStuff() {
try {
val resource = openResource()
callOtherSupendFunction(resource)
} catch (e : CancellationException) {
// never reached here
} finally {
resource.close() // not executed when cancelled
}
}
callOtherSupendFunction()
was a suspendCoroutine{ }
block, which I had to replace with suspendCancellableCoroutine{ }
block to receive the CancellableException.