I have a repository class with an asynchronous method returning User
wrapped into a LiveData
:
interface Repository {
fun getUser(): LiveData<User>
}
In a ViewModel's coruotine scope I want to wait for a result of getUser()
method and use an User
instance.
this is what, I am looking for:
private fun process() = viewModelScope.launch {
val user = repository.getUser().await()
// do something with a user instance
}
I could not find LiveData<>.await()
extension method, and any attempts to implement it.
So before doing it my self, I wonder maybe there is some better way?
All solutions that I have found were about making getUser()
a suspend
method, but what if I can not change Repository
?