nulldev
04/12/2019, 9:32 AMval job = launch(Dispatchers.Default) {
val result = myGiantList.asFlow().filter {
cpuBoundFilter(it)
}.toList()
}
job.cancel()
If I don't do any cancellation checks in cpuBoundFilter
, the flow will continue to filter through everything even though it has been cancelled.Vsevolod Tolstopyatov [JB]
04/12/2019, 9:36 AMnulldev
04/12/2019, 9:37 AMnulldev
04/12/2019, 9:39 AMcpuBoundFilter
completes and then stop filtering right?Vsevolod Tolstopyatov [JB]
04/12/2019, 9:40 AMlist.asFlow
does not suspend anywherenulldev
04/12/2019, 9:48 AMAll the suspending functions in kotlinx.coroutines are cancellable.
in the page you linked me.
I would normally expect the flow to check for cancellation on every iteration of filter.elizarov
04/12/2019, 10:21 AMelizarov
04/12/2019, 10:22 AMnulldev
04/12/2019, 12:34 PMfun <T> Flow<T>.asCancellable() = onEach { if(coroutineContext.isActive) throw CancellationException() }
Vsevolod Tolstopyatov [JB]
04/12/2019, 12:40 PMcoroutineContext.ensureActive
🙂