I have been writting a lot of code that looks like this
class LoginViewModel : ViewModel() {
// A fragment observes this and shows/hides a progressbar
val loader = MutableLiveData<Boolean>()
fun fetchSomeData() = viewModelScope.launch {
loader.postValue(true)
// ...
loader.postValue(false)
}
}
is there a way to do it in a more clean way? if I have to do 100 requests then there will be 200 lines of loader.postValue
// ...
part in your code. (You can leave it as-is for now as your question has already been answered). As an example of a question with more context, see codereview.stackexchange.com/q/279291/31562 \$\endgroup\$