louiscad
03/05/2019, 11:26 AMsuspend fun cancelNow(): Nothing = suspendCancellableCoroutine<Nothing> { c -> c.cancel() }
elizarov
03/05/2019, 11:27 AMthrow CancellationException()
louiscad
03/05/2019, 11:29 AMelizarov
03/05/2019, 11:32 AMlouiscad
03/05/2019, 11:42 AMCancellationException
would be a programmer error, so I think it's always safer to prevent it from working. What do you think about that?
Also, cancellation of the scope would start sooner in case of finally
block, right? If so, I'm wondering why there's no such a cancelNow()
.elizarov
03/05/2019, 11:44 AMelizarov
03/05/2019, 11:45 AMwithContext { ... }
. When something breaks inside it rethrows exception outside, but does not cancel parent coroutine.elizarov
03/05/2019, 11:45 AMlouiscad
03/05/2019, 12:05 PMCompletableDeferred.cancel()
. One may think: Let's catch this CancellationException
, have it working in the case I do throw CancellationException()
, but not working in the case of cancellation by the CompletableDeferred
. I'd not do this mistake, but I'm afraid that someone could do it. That's why I'm thinking something like suspend fun cancelNow(): Nothing
could come handy to make the behavior consistent when there's multiple cancellation cases.elizarov
03/05/2019, 1:44 PM