https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Pacane

05/29/2020, 4:14 PM
I keep hitting those exceptions in one of my scope.launch { } blocks
kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled;
Is there a way to know where this cancellation is coming from? I've put logging+breakpoints everywhere I manually cancel the job, but it's coming from somewhere else..?
f

fatih

05/29/2020, 4:18 PM
Are you launching another Coroutine in this scope. I believe this can happen if you try to launch a new Coroutine after the scope is cancelled.
p

Pacane

05/29/2020, 4:19 PM
I'm using
launch
and
withContext
in that scope, yes
f

fatih

05/29/2020, 4:21 PM
It is hard to tell without a code but where are you cancelling the scope?
p

Pacane

05/29/2020, 4:21 PM
outside the whole thing
c

Casey Brooks

05/29/2020, 4:21 PM
If one job has an error, all its parent jobs are then cancelled. When a job is cancelled, it also cancels all its children. Thus, if a single job has an error, the entire tree of jobs is cancelled. You’ll probably want to to use a supervisorScope to manage independent parallel tasks https://kotlinlang.org/docs/reference/coroutines/exception-handling.html#supervision
p

Pacane

05/29/2020, 4:21 PM
I have an eventbus event, and when it receives a certain type of event it cancels the job
returned from the launch function
gotcha
I'll try that
5 Views