Now in rare conditions line 6 is being executed af...
# coroutines
p
Now in rare conditions line 6 is being executed after I cancelled the job.
v
yes, because you can invoke
cancel
after
render
method started its execution
p
How is that possible?
v
you can boil your example down to:
Copy code
// Thread 1
if (flag) {
   render()
}

// Thread 2
flag = false
do you expect
render
to be invoked when both threads are running concurrently?
p
But what is thread 2?
v
oops, I’ve missed the fact that cancellation is run from the main thread
p
consumeEach is executed on the main thread, right? So how can I cancel it on the main thread if the main thread is running?
v
is
render
a suspend function?
p
No
I can catch the case and send silent crashes to my crash reporting tool.
What should I log to debug this issue?
v
what does
get
do?
is
viewModel
a
CoroutineScope
? Are you cancelling
job
or
viewModel
?
p
viewModel is no CoroutineScope
fun CoroutineScope.get(billingModule: BillingModule, skuDetailSelected: ReceiveChannel<SkuDetail>): ReceiveChannel<VideoPromoState> {
t
You can check coroutineContext [Job] ?. isActive before, after, and inside render ().
p
I can but I shouldn't have to
btw this has moved to a private conversation as I shared confidential code