If I have my presenter that has a `CoroutineScope`...
# coroutines
p
If I have my presenter that has a
CoroutineScope
as a parameter with dagger like
Copy code
fun provideFragmentScope(fragment: MyFragment): CoroutineScope = fragment.lifecycleScope
if on
onDestroyView
I put
lifecycleScope.coroutineContext.cancelChildren()
then is a good praxis to cancel coroutines? Note I'm not using
ViewModel
so I have to cancel it manually...
l
There is no need to cancel coroutines manually even if you don’t use
ViewModel
. I recommend you to take a look at
fragment.viewLifecycleOwner.lifecycleScope
. This lifecycle is slightly different then default one and might suit your needs better.
p
What's the difference? @Lukas Sztefek
I mean, I was having problems because I was trying to cancel a coroutine when the view was not there so it was crashing that's why I'm trying to cancel it
p
So the thing is that on my fragment in the onDestroyView I call lifecycleScope.coroutineContext.cancelChildren() will it get the coroutines from the Presenter? I mean my presenter is the one that is doing some coroutine stuff, so from the fragment I'm cancelling them, is it correct?