Gleno
07/30/2021, 7:24 PMCancellationException
?ephemient
07/30/2021, 7:27 PMNick Allen
07/30/2021, 9:49 PMval task = async {
figureSomethingOut()
}
otherThing.doOnSomeEvent {
result.cancel()
}
val result = try {
task.await()
} catch (e: CancellationException) {
ensureActive()
figureOutSomethingElse()
}
The ensureActive
call will rethrow the CancellationException
if it is meant for the "outer" coroutine.
I'd definitely look for an alternative though rather than write such code just for clarity. For example, join
does throw like await
, and then the Deferred
could be inspected to see if it was cancelled or finished.