首页 > 解决方案 > RxJava:链接两个平面图

问题描述

我有一个getListFromDatabase()返回的方法Single<List<User>> users,以及我想做的事情:

getListFromDatabase()
.flatMap(// send list to another server)
.flatMap(// check if there are users that I have to added manually from a bundle, here I needs database connexion so I have to do this asynchronously, and I need the list I just retrieved)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(// handle onSuccess, onError etc.)

但在第一个 flatMap 中,它一直在告诉我missing return statement。我没有弄清楚什么是正确的语法?

标签: rx-java2

解决方案


getListFromDatabase()
.flatMap(users -> sendAnotherService().map(ingoreResult -> users))
.flatMap(// check if there are users that I have to added manually from a bundle, here I needs database connexion so I have to do this asynchronously, and I need the list I just retrieved)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(// handle onSuccess, onError etc.)

其中 sendAnotherService() 返回具有任何类型 arg 的 Single。


推荐阅读