Is intermediate flow operators are cancellable? Ar...
# flow
f
Is intermediate flow operators are cancellable? Are they cancelled when the calling scope is cancelled? For instance:
Copy code
// If the collecting scope is cancelled before this map operation,
// seems like map operation is not cancelled and throws an exception
numbersFlow.map {
    // There is an operation which throws exception
}
.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
I have to use
ensureActive()
before mapping but is it the expected behaviour?
I can also use
catch
but just curious why it is not cancelled itself since the calling scope is cancelled
Ok. Intermediate operators are not suspend functions and this is why they are not cancellable like normal coroutine suspend functions. They are in deed normal functions. So
ensureActive
or
isActive
should be used. https://github.com/Kotlin/kotlinx.coroutines/issues/1460#issuecomment-523985861