Lilly
03/29/2021, 8:58 AMcoroutineScope {
launch {
if (condition) cancel() // does not cancel the coroutine of flow
}
launch {
dataSource.channel.receiveAsFlow() {
.collect { doSomething() }
}
}
I would expect that cancelling first coroutine would cancel second coroutine but it doesn't. Any ideas?louiscad
03/29/2021, 9:20 AMCancellationException
), but I guess what you're looking for here is doing this@coroutineScope.cancel()
.Albert Chang
03/29/2021, 9:39 AMlaunch
will create a new CoroutineScope
for the job which is different from the outer scope. You are canceling the inner scope so it won't affect other jobs in the outer scope.Lilly
03/29/2021, 9:44 AMcoroutineScope
states: "When any child coroutine in this scope fails, this scope fails and all the rest of the children are cancelled". My example macthes this statement exactly, not?Albert Chang
03/29/2021, 9:46 AMCancellationException
.Lilly
03/29/2021, 9:46 AMlouiscad
03/29/2021, 9:46 AMLilly
03/29/2021, 9:47 AM