You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the given [context] does not contain a [Job] element, then a default Job() is created.
This way, cancellation or failure of any child coroutine in this scope cancels all the other children,
just like inside [coroutineScope] block.
The key confusion here is that cancellation of any child coroutine in this scope cancels all the other children. From my testing, cancellation of a child of a Job() doesn't really cancels all other children. Maybe I'm missing anything but the testing code is:
val scope = CoroutineScope(Dispatchers.Default)
// Or more explicitly val scope = CoroutineScope(Dispatchers.Default + Job())
val job1 = scope.launch {
delay(99999)
}
val job2 = scope.launch {
delay(500)
}
job2.cancel()
println("job1 state: ${job1.isCancelled}") // false
println("job2 state: ${job2.isCancelled}") // true
The text was updated successfully, but these errors were encountered:
So I've noticed that the doc says
The key confusion here is that cancellation of any child coroutine in this scope cancels all the other children. From my testing, cancellation of a child of a Job() doesn't really cancels all other children. Maybe I'm missing anything but the testing code is:
The text was updated successfully, but these errors were encountered: