Hello, I'm wondering where is it best on Android t...
# coroutines
r
Hello, I'm wondering where is it best on Android to launch a coroutine for a simple post to a server. Let's say I have a button on a Fragment that call a function in a Viewmodel that call a function in a Repository. Should I launch the coroutine in the Fragment, the Viewmodel or the Repository?
w
You’re likely going to want to implement
CoroutineScope
in your ViewModel, that way coroutines started for things like network calls are tied to the ViewModel
d
I prefer
ViewModel
where you can provide an appropriate scope for the coroutine
☝️ 2
👍 3
✔️ 1
r
thank you good sirs
w
Needs the alpha version though.