https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

eygraber

08/13/2020, 9:02 PM
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

octylFractal

08/13/2020, 9:03 PM
do you not make the
resume
call yourself?
s

streetsofboston

08/13/2020, 9:04 PM
Yup, either right before/after every call to
cont.resume(…)
or after the
suspendCancellableCoroutine { … }
itself.
e

eygraber

08/13/2020, 9:05 PM
I guess I have a lot of fixing to do 🙂
o

octylFractal

08/13/2020, 9:05 PM
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

streetsofboston

08/13/2020, 9:06 PM
The
resume
function does not return a `Nothing`…. code that is after a call to
resume
should be executed, shouldn’t it?
o

octylFractal

08/13/2020, 9:07 PM
yes, but not until it is either re-dispatched or completes
s

streetsofboston

08/13/2020, 9:07 PM
I see… yup, safer bet would be to call it before 🙂
o

octylFractal

08/13/2020, 9:09 PM
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
3 Views