Tomas Kormanak
09/07/2021, 12:42 PMcoroutineScope {
val job1 = launch { foo() }
val job2 = launch { bar() }
delay(1000)
job1.cancel()
job2.cancel()
}
Tomas Kormanak
09/07/2021, 12:44 PMcoroutineScope {
launch { foo() }
launch { bar() }
delay(1000)
cancel()
}
but it closes parent scope as well.Richard Gomez
09/07/2021, 1:03 PMTomas Kormanak
09/07/2021, 1:06 PMsupervisorScope
does not propagate exceptions and does not close itself when child job fails. But when I cancel supervisorScope, it cancels parent scope as well. I might be missing something.Richard Gomez
09/07/2021, 1:09 PMCancels all children jobs of this coroutine using Job.cancel for all of them with an optional cancellation cause. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected.https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/cancel-children.html
Tomas Kormanak
09/07/2021, 1:58 PMlaunch{
coroutineScope {
launch { foo() }
launch { bar() }
delay(1000)
cancel()
}
}