Katarzyna
09/29/2021, 8:21 AMVishnu Haridas
09/30/2021, 12:18 PMscopeA.launch(SupervisorJob()){ // coroutineX
launch {
// coroutineY
}
launch {
// coroutineZ
}
}
the result will be:
[scopeA+SupervisorJob()]
- [ScopeA+Job()] runs coroutineX
- [ScopeA+Job()] runs coroutineY
- [ScopeA+Job()] runs coroutineZ
So an exception in coroutineY will propagate up, and cancels coroutineZ also.
The Job or CoroutineContext passed to the launch actually gets added to the receiver scope of the launch call, and the launched coroutine actually creates a new scope and its own Job. It gets a little bit to wrap the head around it 🤯
This is an excellent article by Roman E: https://elizarov.medium.com/coroutine-context-and-scope-c8b255d59055