Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why method with Flowable<List> of Room DAO never completes?

Fetching data from DB , Room DAO has a method that returns a Flowable userDao.getInfo(), this Flowable will never completes, I tested adding doOnNext() it emits 5 times (DB contains 5 items) but complete is never called, but I need as I have toList(),what could be the alternative for this

return userDatas()
    .flatMapIterable(items -> items)
    .flatMap(userData -> userDao.getInfo(userData.getId())
        .map(user -> user.toStoreModel(...)//added doOnNext()-works 5 times and doOnComplete()doesn't work
  .doOnNext(userData -> Log.i("test",""+userData))
    .doOnComplete(() -> Log.i("test","complete"))
        .toList()
        .map(UserModel::fromUserModels)
        .toFlowable();


@Query("SELECT * FROM user WHERE id = :id") 
Flowable<...> getInfo(Long Id);

  public Flowable<List<UserStore>> userDatas() {
return userDao.allUserDatas()
    .take(1)//added complete and next works 
    .filter(userDatas -> !userDatas.isEmpty())
    .switchIfEmpty(userIds()
        .doOnNext(userDatas -> userDao.insert(userDatas)));

 }

I have tested and even when I'm replacing userDatas() only with userDao.allUserDatas() (I'm sure it exists in DB) it gives the same results

like image 974
I.S Avatar asked Dec 11 '25 17:12

I.S


1 Answers

Everything is ok with your code ,it would never complete Db Flowables are observable ,so they keep listening if database changes, so it never completes.

like image 97
I.S Avatar answered Dec 13 '25 09:12

I.S