Rxjava tolist() 未完成 [英] Rxjava tolist() not completing

查看:55
本文介绍了Rxjava tolist() 未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 RxJava 调用链有问题.toList 工作不正常.我猜是 toList() 需要完成一些事情.这就是它被卡住的原因.但我不知道如何解决这个问题

I have a problem with my RxJava callchain. The toList is not working properly. I would guess that it is that the toList() needs something to complete. That is why it is stuck. But i do not know how to solve this issue

代码

        mModel.getLocations()
            .flatMapIterable(new Function<List<Location>, List<Location>>(){
                @Override
                public List<Location> apply(final List<Location> locations) throws Exception {
                    return locations;
                }
            })
            .filter(new Predicate<Location>() {
                @Override
                public boolean test(final Location location) throws Exception {
                    return location.searchExistInNameOrKeyWord(input);
                }
            })
            .toList()
            .map(new Function<List<Location>, List<Location>>() {
                @Override
                public List<Location> apply(List<Location> locations) throws Exception {                     
                    /** Doing some random work with the list and then returning */
                }
            })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<List<Location>>() {
                @Override
                public void accept(final List<Location> locations) throws Exception {
                    mView.setAdapterItems(locations);
                }
            });

也许在 RxJava 方面比我强得多的人可以指出我做错了什么.

Maybe someone that is a lot better than me at RxJava could pinpoint what i am doing wrong.

更新

@Query("SELECT * from location")
Flowable<List<Location>> loadAllLocations();

mModel.getLocations() 只是从 Room percistance 存储中调用上面的 loadAllLocations

The mModel.getLocations() just calls the loadAllLocations like above from the Room percistance storage

推荐答案

我以前从未使用过 Room 但根据这篇文章:https://medium.com/google-developers/room-rxjava-acb0cd4f3757

I've never used Room before but according to this article: https://medium.com/google-developers/room-rxjava-acb0cd4f3757

现在,每次用户数据更新时,我们的 Flowable 对象都会自动发射,允许您根据最新的用户界面更新数据.Flowable 只会在查询结果包含 at 时发出至少一排.当没有数据匹配查询时,Flowable不会发出,无论是 onNext 还是 onError.

Now, every time the user data is updated, our Flowable object will emit automatically, allowing you to update the UI based on the latest data. The Flowable will emit only when the query result contains at least a row. When there is no data to match the query, the Flowable will not emit, neither onNext nor onError.

因此,Flowable 会对每次数据更改做出反应,这意味着永远不会调用 onComplete.在这种情况下,您不能使用 toList() 运算符,因为此流永远不会完成.

So, Flowable reacts on every data change and that means onComplete would never be called. In that case you cannot use toList() operator because this stream will never complete.

这篇关于Rxjava tolist() 未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆