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

Se7eN

09/17/2020, 6:56 PM
This may sound stupid but believe me when I do
users.postValue(repository.getUsers(20))
, the getUsers function executes but the value isn't posted but when I do
list = repository.getUsers(20)
and then do
users.postValue(list)
it works totally fine. What's the deal here?
The data is being loaded correctly in both cases but it's not being posted to
users
livedata in the first case. Also, I'm using
viewModelScope.launch
, if it matters
i

Ian Lake

09/17/2020, 7:07 PM
It seems like
repository.getUsers()
should just return a
LiveData
?
s

Se7eN

09/17/2020, 7:10 PM
Yeah it could but I'm trynna figure out why this is happening
Anyways I don't like to keep
LiveData
in my repository so I'm using the
liveData
builder now
i

Ian Lake

09/17/2020, 8:24 PM
You're probably just better off having it return a
Flow
the entire way up, then use
asLiveData()
to convert it over in your ViewModel
2
s

Se7eN

09/18/2020, 9:04 AM
Yeah I guess I'll use a flow when I add network state. Don't even need LiveData since I'm using jetpack compose so I'll just observe the flow as state
4 Views