Tolriq
11/02/2018, 10:03 AMJob() + Dispatchers.Main
create a new context and parent job? (The Android lifecycle part I master after all those years:p) and calling coroutineContext.Cancel() does cancel the parentJob and all the child + prevent new calls, and that coroutineContext.CancelChildren() only cancel running jobs for that context/job and allows queuing new ones?louiscad
11/02/2018, 10:28 AMcancelChildren()
deprecated? BTW, you should use SupervisorJob()
for the lifecycle bound scope.Tolriq
11/02/2018, 10:45 AMTolriq
11/02/2018, 10:48 AMSupervisorJob
for that purpose, only difference seems to be about exception moving up or not.louiscad
11/02/2018, 10:53 AMlouiscad
11/02/2018, 10:53 AMTolriq
11/02/2018, 10:57 AMlouiscad
11/02/2018, 10:59 AMlouiscad
11/02/2018, 11:00 AMSupervisorJob
Tolriq
11/02/2018, 11:02 AMFailure or cancellation of a child with an exception other than CancellationException immediately cancels its parent.
and from my tests it works.Tolriq
11/02/2018, 11:03 AMTolriq
11/02/2018, 11:03 AMTolriq
11/02/2018, 11:03 AMgildor
11/02/2018, 1:07 PMand from my tests it works.Probably your tests are wrong or do not cover such case If one of coroutines in your scope with Job() throws exception parent scope and all child coroutines will be cancelled
Tolriq
11/02/2018, 1:28 PMlouiscad
11/02/2018, 1:30 PMasync
block that you catch at await
time, the scope will still be cancelled unless it's a supervisor. That why supervisor is there, and that's why you should use it.Tolriq
11/02/2018, 1:40 PMlouiscad
11/02/2018, 1:48 PMTolriq
11/02/2018, 1:54 PMTolriq
11/02/2018, 1:54 PMlouiscad
11/02/2018, 1:56 PMTolriq
11/02/2018, 1:59 PMlouiscad
11/02/2018, 2:11 PMcancel()
, and of course, there's no way cancelChildren()
should cancel the parent too.Tolriq
11/02/2018, 2:30 PM