Let's say you are within a suspend function... Wha...
# coroutines
r
Let's say you are within a suspend function... What's the most pragmatic way to cancel your execution? Should you just throw a cancellation exception? Or maybe somehow grab the current job and cancel that?
My use case: I have a third party "cancellation token" i want to check within a suspend function to see if cancellation has been requested. If so, i want to just cancel current suspend function
z
To cancel the current coroutine, throw an exception. If you just cancel the job, then your coroutine will continue to execute until something suspends or checks the job status.
r
@Zach Klippenstein (he/him) [MOD] yeah my plan was to do both. Cancel current job and then throw cancellation exception
z
Just throwing the exception should be enough. Otherwise the job will logically have two cancellation exceptions, which is confusing.
r
True. Thanks i think I'll just throw!