Sudhir Singh Khanger
06/03/2021, 4:25 AMrunBlocking {
val scopeJob = Job()
val scope = CoroutineScope(scopeJob)
val job = scope.launch {
}
}
I am unclear on whether job
and scopeJob
are the same. They seem to print different job ids. job
is the Job returned from scope.launch construct in which I have passed a context which which has scopeJob assigned to it. So they should be the same?baxter
06/03/2021, 4:40 AMjob
is a child of scopeJob
. If you do a printout of all child jobs of scopeJob
, you'll see that job
is part of it.
runBlocking {
val scopeJob = Job()
val scope = CoroutineScope(scopeJob)
val job = scope.launch {
}
scopeJob.children.forEach {
println("Child: $it")
}
println("job $it")
}
If you were to cancel scopeJob
, job
would also be cancelled.