kevin.cianfarini
03/23/2020, 8:15 PMDennis
03/23/2020, 8:19 PMoctylFractal
03/23/2020, 8:20 PMSupervisorJob()
kevin.cianfarini
03/23/2020, 8:22 PMIf parent job is specified, then this supervisor job becomes a child job of its parent and is cancelled when its parent fails or is cancelled. All this supervisor’s children are cancelled in this case, too. The invocation of cancel with exception (other than CancellationException) on this supervisor job also cancels parent.
octylFractal
03/23/2020, 8:23 PMSupervisorJob()
is for the scope you don't want cancelledkevin.cianfarini
03/23/2020, 8:24 PMCoroutineScope by CoroutineScope(Dispatchers.Main.immediate + SupervisorJob())
octylFractal
03/23/2020, 8:25 PMcancel()
on the scope itself?kevin.cianfarini
03/23/2020, 8:25 PMthis.cancel
which is the problem. It's cancelling the scope itselfoctylFractal
03/23/2020, 8:26 PMkevin.cianfarini
03/23/2020, 8:27 PMoctylFractal
03/23/2020, 8:27 PMthis.coroutineContext[Job]!!.children.forEach { it.cancel() }
kevin.cianfarini
03/23/2020, 8:27 PMCoroutineScope.cancelChildren
should be a thingDominaezzz
03/23/2020, 8:44 PMcancelChildren
is indeed a thing.kevin.cianfarini
03/23/2020, 8:45 PMthis.coroutineContext[Job]!!.cancelChildren()
Dominaezzz
03/23/2020, 8:48 PMthis.coroutineContext.cancelChildren()
should also be possible iirc.kevin.cianfarini
03/23/2020, 8:49 PMDominaezzz
03/23/2020, 8:50 PMCoroutineScope
!= Job
. The separation of CoroutineScope
, CoroutineContext
and Job
is a bit.... weird though, but I'm not sure if I could do better myself.kevin.cianfarini
03/23/2020, 8:52 PMchildren
.
CoroutineScope should be implemented (or used as a field) on entities with a well-defined lifecycle that are responsible for launching children coroutines. Example of such entity on Android is Activity. Usage of this interface may look like this:To me, that is justification enough itself to include a cancelChildren on this considering the other mechanisms that have children have this functionality.
araqnid
03/23/2020, 8:53 PMkevin.cianfarini
03/23/2020, 8:54 PMaraqnid
03/23/2020, 8:55 PMkevin.cianfarini
03/23/2020, 8:57 PMCoroutineScope.cancelChildren
would in effect be syntactic sugar for that. It feels cumbersome to be to necessitate making a singular ephemeral CoroutineScope for this kind of thing.araqnid
03/23/2020, 9:00 PMgildor
03/25/2020, 3:28 PM