因此,这就是我尝试使用Flow
的过程,我在ProgressBar
中显示onStart
,并试图在ProgressBar
中隐藏onCompletion
在ViewModel类中,appDatabase.eventDao().getAllEvents()
返回Flow<List<EntityEvents>
@ExperimentalCoroutinesApi
val allEvents: LiveData<Outcome<List<Event>>> = _fetchEvents.switchMap { _ ->
appDatabase.eventDao().getAllEvents()
.map { eventListMapper.map(it) }
.map { sortEventsBasedOnPreference(it) }
.flowOn(Dispatchers.IO)
.map { Outcome.success(it) }
.onStart { emitLoading(true) }
.onCompletion { emitLoading(false) }
.catch { emitFailure(it, R.string.err_something_wrong) }
.asLiveData(context = viewModelScope.coroutineContext)
}
一切正常,我无法弄清楚为什么在任务完成时没有调用onCompletion
?