Lukas Lechner
08/05/2020, 6:55 AM.cancel()
on the job of the scope VS calling .cancel()
on the scope itself? Lots of blogpost recommend to keep a reference to the job
in order to be able to cancel it, although IMO this is not necessary, as cancelling the scope itself has the exact same effect. Am I correct?trevjones
08/05/2020, 6:57 AMtrevjones
08/05/2020, 6:58 AMefemoney
08/05/2020, 6:59 AMJob
) might contain more coroutines than the individual job, which represents a subtree of coroutines in the wider scope’s tree of coroutines.octylFractal
08/05/2020, 6:59 AMandylamax
08/05/2020, 9:53 AMefemoney
08/05/2020, 9:57 AMJob
element in that scope’s CoroutineContext
and that job is the parent of all the jobs for all the coroutines launched within that scope. At the end of the day the rules of job cancellation still apply to the scope(’s Job
)bdawg.io
08/07/2020, 5:20 AMval job = Job()
val scope = CoroutineScope(job)
for (i in 1..100_000) scope.launch { ... }
job.cancel()
vs
val scope = CoroutineScope(Job())
for (i in 1..100_000) scope.launch { ... }
scope.cancel()