Very simple question I suppose. What are the impli...
# coroutines
e
Very simple question I suppose. What are the implications of not canceling a
CoroutineScope
at the end of its lifecycle? Example of scope:
Copy code
private val myOwnScope = CoroutineScope(Dispatchers.MY_DISPATCHER + SupervisorJob() + CoroutineName("..."))
If I'm not interested in canceling the children jobs, should I still cancel it?
s
Cancelling the coroutine scope is just a shortcut for cancelling the job in the scope’s context. It doesn’t do anything else besides that.
Failing to cancel jobs is a potential issue in itself, though. For example, if those jobs are holding resources like open network connections, the resources might not be released.
e
Thanks Sam, makes sense! In my case the jobs are guaranteed to not hold any kind of resource, but I'll see how to abstract/wrap the cancellation so it's done anyway
👍 1
r
Yep, it's your scope so it's up to you to define what "end of its lifecycle" even means. If the lifecycle is "the entire lifetime of the process" then clearly there's no reason to ever cancel. If it's tied to some other component's lifetime then it's implied by the contract that any work started will not outlive the component
gratitude thank you 1