https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

Romain

03/11/2019, 2:15 PM
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

withoutclass

03/11/2019, 2:17 PM
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

dgngulcan

03/11/2019, 2:17 PM
I prefer
ViewModel
where you can provide an appropriate scope for the coroutine
☝️ 2
👍 3
✔️ 1
r

Romain

03/11/2019, 2:19 PM
thank you good sirs
w

withoutclass

03/11/2019, 2:22 PM
Needs the alpha version though.
3 Views