We have code similar to this: ``` val job = launch...
# coroutines
We have code similar to this:
Copy code
val job = launch {
    val flow = slowBlockingCallThatReturnsIterator().asFlow()
    flow.collect { 
        yield() // allows for cancel() to work
If we call
during the slowBlockingCall (or while the flow is collecting) without the
call, all entries in the iterator still get sent to the channel. If we add back the yield call, then the collection aborts as we initially expected to happen without the yield(). Since channel.send is a suspend function, shouldn't calling it check the coroutine active state?
No, suspension on its own does not check for cancellation, because that's not part of the language, it's part of coroutines lib
does check for it, but only if it suspends:
Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.
ah ok, thanks. I missed that, but saw the
All the suspending functions in kotlinx.coroutines are cancellable
doc that made me think otherwise