android - 当 flowable 发射时从单个发射
问题描述
我有一个活动,您可以根据过滤器和地图的当前视口看到一堆地方。
所以我将这两个来源建模为Flowables
:
fun boundariesFlowable(): Flowable<Pair<LatLon, LatLon>>
fun filtersFlowable(): Flowable<FilterRequest>
边界发出地图视口的左上角和右下角,过滤器只发出用户应用的过滤器的任何变化。
现在我想观察这两个来源,以便每次它们中的任何一个发生变化时都会执行一次调用。这是我的请求电话:
fun refreshApplyFilter(id: Int, filter: FilterRequest): Single<FilterResponse>
问题是,我无法弄清楚如何组合这个触发源,或者如何对它们的发射执行调用。
我已尝试仅对其中一个源进行平面映射,但它需要 a Publisher
,而我的请求是Single
.
解决方案
您可以使用Flowable.combineLatest()运算符来观察多个来源。如果其中任何一个发布新值,将触发函数。
val res: Flowable<FilterResponse> = Flowable.combineLatest(boundariesFlowable(), filtersFlowable(), BiFunction<Pair<LatLon, LatLon>, FilterRequest, FilterRequest> { pair, filter ->
filter
}).flatMapSingle { filter -> refreshApplyFilter(0, filter) }
推荐阅读
- java - 获取数据库的bean名称(动态)
- c# - 使用 dotnet core 查找 linux 文件类型
- matlab - MATLAB 中的两个 for 循环,一个不工作
- sql - 查询以获取 BI 发布器中参数的工作表管理器层次结构
- python - 在 Flask 应用程序中保持全局状态
- cookies - .net core 是否可以支持多个 cookie 域?
- c# - System.Net.Http.WinHttpException:发生安全错误
- d3.js - 动画线图线
- app-engine-flexible - 如何获取在灵活环境中运行的 Java 应用程序的堆转储
- angularjs - Froala 编辑器在编辑时崩溃