```val jobA = Job() val jobB = GlobalScope.launch(...
# coroutines
s
Copy code
val jobA = Job()
val jobB = GlobalScope.launch(jobA) {
    delay(1000L)
    println("World!")
}
What is the different between
jobA
and
jobB
? If I would like to cancel the Job, which one need to be called?
jobA.cancel()
or
jobB.cancel()
? Thread in Slack Conversation
l
jobA
is parent of
jobB
🙆‍♂️ 1
cancelling
JobA
cancels all of its children jobs
cancelling
jobB
only cancels itself
s
I got it. Thank you.
a
wouldn’t jobB cancel also jobA since is its child?
l
this would be the case if
jobB
fails, but only calling
.cancel()
on it has no effect to the parent
a
perfect, that’s what I meant, terminating exceptionally would kill also jobA
👍 1
s
If a child job ends abnormally, either through cancellation or through an exception, its parent is cancelled (if the parent is not a SupervisorJob). The cancelling of the parent job then will cause the sibling jobs to be cancelled as well. The difference between plain cancellation (through a CancellationException or a sub-class of it) and an error-termination (any other exception) is that the CoroutineExceptionHandler is not called on a plain cancellation.