Hello on my presenter I'm getting a `CoroutineScop...
# coroutines
p
Hello on my presenter I'm getting a
CoroutineScope
and a
CoroutineDispatcher
is it mandatory to implement in the
onDestroy()
the cancel of them? what happens if I don't do this?
a
It is mandatory to do so so that you may not have leaking coroutines running while the scope of your presenter is destroyed
p
So, it's mandatory that on every onDestroy of an Activity/Fragment I do coroutineScope.cancel() and coroutineDispatcher.cancel()?
a
Just the scope. No need to cancel the dispather
i
Note that Activities and Fragments already have a scope that is cancelled for you in onDestroy(): https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescope
p
@Ian Lake  thanks for this note though, the thing is, my fragment/Activity have a @Inject lateinit var myPresenter : Presenter And this presenter already have as a parameter a 
MainScope()
 , so, even if they cancell their own scope they won't cancell the one created on my presenter, right?
i
Unless you hook up the
lifecycleScope
as the parent scope, it won't automatically cancel, that's correct
p
And if I use myActivity.lifecycleScope then it's not necessary to cancel in the onDestroy, right? @Ian Lake
i
It will do that automatically, yes
👍🏽 1