For example ``` val rootJob = Job() val rootContex...
# coroutines
b
For example
Copy code
val rootJob = Job()
val rootContext = Dispatchers.Default + rootJob

val otherJob = Job()
val otherScope = object : CoroutineScope {
    override val coroutineContext = rootContext + otherJob
}
otherScope.doSomethingAsync()
otherScope.doSomethingElseAsync()

rootJob.cancel() // will this cancel items from otherJob?
d
With this particular code, no. But normally, if you launch a coroutine in a scope with a Job, it is a child of that job. That relation isn't established when you do
rootContext + otherJob
, where the value associated with
[Job]
key is simply dropped.
b
So should I be checking if a
[Job]
is present and passing it as the
parent
of the
otherJob
? If I do that, will
otherJob
being cancelled cause the
rootJob
to cancel too (undesirably in my case)?
g
What do you want to achieve? If you explicitly use different Jobs for different coroutines there are no relationships between them, in your example above you just replace one job with another.