https://kotlinlang.org logo
Title
p

Paul Woitaschek

02/02/2019, 9:22 PM
Currently I have a
suspend fun <http://CoroutineContext.xyz|CoroutineContext.xyz>()
and I perform a check and then call
coroutineContext.cancel()
and then throw a
CancellationException
.
a

Allan Wang

02/02/2019, 9:22 PM
What do you mean by check? Also note that whenever you switch contexts (withContext), the runnables will automatically not be called if the coroutine is cancelled
a

Allan Wang

02/02/2019, 9:23 PM
If you also just want to insert breakpoints during an execution, you can use
yield()
p

Paul Woitaschek

02/02/2019, 9:23 PM
So you suggest to just throw the exception?
a

Allan Wang

02/02/2019, 9:23 PM
Throwing alone should work
You also might not want to use both
suspend
and
CoroutineScope
extensions in one method. Suspending functions are long executions whereas coroutine scope functions launch and return quickly
p

Paul Woitaschek

02/02/2019, 9:26 PM
It was only to cancel the job
Thanks!