I've been (incorrectly it seems) assuming that `Co...
# coroutines
e
I've been (incorrectly it seems) assuming that
Continuation.invokeOnCancellation
will be invoked after resuming, and I've been relying on it for internal cleanup. Is there any way to register a callback for when a continuation resumes, or do I need to handle it manually at all the resume points?
o
do you not make the
resume
call yourself?
s
Yup, either right before/after every call to
cont.resume(…)
or after the
suspendCancellableCoroutine { … }
itself.
e
I guess I have a lot of fixing to do 🙂
o
I would do it before the call to
cont.resume
, as undispatched continuations will prevent your code from continuing to run, but that may not be possible in some cases
s
The
resume
function does not return a `Nothing`…. code that is after a call to
resume
should be executed, shouldn’t it?
o
yes, but not until it is either re-dispatched or completes
s
I see… yup, safer bet would be to call it before 🙂
o
though tbh, if you're in a
kotlinx.coroutines
context (i.e. using Job), most coroutines will be re-dispatching to
Default
or similar, so it may not be a huge deal