Proper way to pass LiveData in ViewModel taken from suspended Repository
There is a liveData builder that can call suspend functions in its body. So your view model function can look like
fun getMountains() = liveData {
emit(mountainsRepository.getAll())
}
make sure you are using at least
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
And as Lena mentioned - removing suspend
from your repository getAll()
function do not make it blocking.
Having
fun getAll() : LiveData<List<Mountain>>
in your repo, and
fun getMountains() = mountainsRepository.getAll()
in your view model, could be a better way to achieve the same goal