Ruben Quadros
02/19/2022, 8:11 AMCoroutineScope
as a dependency which every module can access then we can launch different coroutines using this one scope? Each child coroutine can then have its own CoroutineExceptionHandler
as well. Is my understanding correct?Sam
02/19/2022, 8:16 AMSam
02/19/2022, 8:17 AMSam
02/19/2022, 8:26 AMSam
02/19/2022, 8:29 AMall children coroutines (coroutines created in the context of another Job) delegate handling of their exceptions to their parent coroutine, which also delegates to the parent, and so on until the root, so the CoroutineExceptionHandler installed in their context is never used.
https://kotlinlang.org/docs/exception-handling.html#coroutineexceptionhandler
Ruben Quadros
02/19/2022, 8:33 AMSupervisorJob
context?Sam
02/19/2022, 8:35 AMcoroutines launched directly inside the supervisorScope do use the CoroutineExceptionHandler that is installed in their scope in the same way as root coroutines do
https://kotlinlang.org/docs/exception-handling.html#exceptions-in-supervised-coroutines
Ruben Quadros
02/19/2022, 8:39 AMSam
02/19/2022, 8:43 AMwe can also keep track of coroutines launched using the single scope and make sure to cancel them once they are no longer required?
That's touched on by Roman in his article about GlobalScope, which I linked to above. He basically says that manually keeping track of all your coroutines would work, but it would get quite complicated, and scopes make it much simpler.