Marc Knaup
05/26/2020, 9:31 AMwithContext
check for cancelation upon before and/or after invoking block
?
Will yield
check for cancelation immediately or on/after dispatch?bezrukov
05/26/2020, 10:07 AMWill a suspending function call check for cancelation before the function implementation is invoked?it's heavily depends on suspend fun implementation, by default suspend fun is not cancellable out of the box, so it needs to be designed to support cooperative cancellation (e.g. use built-in primitives or check for coroutine state).
WillShould be both in generalcheck for cancelation upon before and/or after invokingwithContext
?block
Willcheck for cancelation immediately or on/after dispatch?yield
yield
will check it immediately, but will also resumed with exception if job was cancelled before re-dispatching. Also consider ensureActive
for checking for cancellation in your non-cancellable codeMarc Knaup
05/26/2020, 10:15 AMensureActive
. That seems helpful given that suspend fun
don’t check for cancelation by default (unless it calls others that do).
Do you happen to know a good open source example/library/app that properly manages various scopes & contexts and thus can serve as guidance?louiscad
05/26/2020, 12:08 PMwithContext
since I don't recall which kotlinx.coroutines version does check for cancellation before and after invoking block using its given context (which, in case of NonCancellable
, will be prevented).uli
05/26/2020, 2:28 PMSuspend(Cancelable)Coroutine
, yield
, withContext
, await
, and funs calling one of the above. what did i forget?octylFractal
05/26/2020, 5:10 PMlouiscad
05/26/2020, 7:26 PMJob
.
FYI, the "x" in kotlinx stands for extension.octylFractal
05/26/2020, 8:14 PMlouiscad
05/26/2020, 8:58 PMMarc Knaup
05/27/2020, 7:16 AM