Should I make a suspend network call in a `viewMod...
# coroutines
k
Should I make a suspend network call in a
viewModelScope
or inside compose function with side-effect with compose?
Are there any drawbacks calling suspend function inside
viewModelScope
?
z
Network calls aren’t usually a UI concern, unless it’s something like loading images, so it usually doesn’t make sense to do them in the view layer.
👍 3
j
@K Merle you should do network call somewhere in your repositories. Then inject your repositories to your constructor
viewModel
then do call the repositories inside your
viewModelScope
as usually its suspend function.
a
A nice thing about questions like this is that the functional requirements usually give you your answer. When should the network call cancel and stop doing work? What code owns the result?
2