Advertisement
Guest User

Untitled

a guest
Apr 27th, 2021
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. fun test() = flow {
  2. val result: MutableList<DataItem> = ArrayList()
  3. emit(Resource.Loading(data = null))
  4. result.clear()
  5. colorDao.getDatesFlow().collect {
  6. it.forEach {
  7. result.add(
  8. DataItem(
  9. it,
  10. colorDao.getColorsByDate(it)
  11. )
  12. )
  13. }
  14. try {
  15. emit(Resource.Success(data = result))
  16. result.clear()
  17. } catch (exception: Exception) {
  18. emit(Resource.Error(data = null, message = exception.message ?: "Error Occurred!"))
  19. }
  20. }
  21. }.asLiveData()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement