Андрей Коровин
08/26/2021, 3:57 PMviewLifecycleOwner.lifecycleScope.launchWhenStarted {
viewModel.news.collect {
}
}
In ViewModel:
private val newsFlow = refreshTrigger.flatMapLatest {
repository.getNewsArticles()
}
val news = newsFlow.stateIn(viewModelScope, SharingStarted.Lazily, null)
In Repository:
fun getNewsArticles() = channelFlow<Resource<List<NewsArticle>>> {
try {
newsArticleDao.getNews().collect { send(Resource.Success(listOf(NewsArticle("asfas", "asfas", "asfas")))) }
}
catch (e: Throwable) {
Log.e("TEST", "error", e)
}
}
I send value to refresh trigger when a user does swipe refresh. And each time they do it, I get the following exception in the Repository code:
E/TEST: error
kotlinx.coroutines.flow.internal.ChildCancelledException: Child of the scoped flow was cancelled
Can anyone explain whether it’s right behaviour or am I doing something wrong? Didn’t find a solution how to fix it. This is the most relevant post I found.