Skip to content

Conversation

@gmiklay
Copy link

@gmiklay gmiklay commented Sep 5, 2019

Hello Mitch!

I experimented with coroutines and found that immediate cancellation only works if there is a delay function in the coroutine. In other words, if we replace the delay with a lengthy(250000 instead of 100) for loop, it will continue to run until the loop ends at 250000 (you can see it in the log.d) and then run into the cancellation phase. I think it only good for garbage collection, not for immediate cancellation.

The cause why delay function works is this code:
return suspendCancellableCoroutine sc@ { cont: CancellableContinuation ->
cont.context.delay.scheduleResumeAfterDelay(timeMillis, cont)
}

This code suspends/delays the Coroutine. While suspended the cancellation is immediate. That's why it works.

There is another branch with my solution of immediate cancellation. I make a pull request tfor that also.

Thx
Gabor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants