Is there something similar to `yield` that does no...
# coroutines
p
Is there something similar to
yield
that does not dispatch if
isDispatchNeeded == false
?
Context is I’m starting a coroutine with
CoroutineStart.UNDISPATCHED
but at some point I want to check for cancellation and run the code in the correct coroutine context present in scope, but I want to avoid dispatch if dispatcher is immediate and it was already called in the right thread
b
If you are only interested in cancellation, you may use
ensureActive
instead https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/ensure-active.html
p
@bezrukov no, because it’s started undispatched (random caller thread) and ensureActive would not dispatch it if needed