How to await for value using Coroutines with viewModelScope
How to await for value using Coroutine suspend method in viewModel in most efficient way.
My solution for now:
viewModelScope.launch {
val item = async { itemRepository.getItem(id) }.await()
print("log me after not null $item)
}
Kotlin converts it to and the question is also why? :)
viewModelScope.launch {
withContext(Dispatchers.Default) {
itemRepository.getItem(id)
}
print("log me after not null $item)
}...