【发布时间】:2018-10-05 10:42:44
【问题描述】:
这个问题很复杂,但代码看起来更简单(我希望)
我有一个像下面这样的功能
fun trackFoos(): Observable<List<Foo>> {/*....*/}
fun getBarForFoo(fooState: Foo.State): Single<Bar>
而且我有一些代码绑定到应用程序的其他部分,所以我不能改变太多。
Observable.combineLatest(
trackFoos(),
Observable.interval(1, TimeUnit.SECONDS),
BiFunction() {foos: List<Foo>, _:Long -> foos}
).subscribe { foos -> /*....*/ }
现在我还需要使用 getBarForFoo 为每个 foo 对象传递 Bar 对象
所以我需要使用trackFoos() 和getBarForFoo() 编写trackPairOfFooAndBar() 来使用它,如下所示:
Observable.combineLatest(
trackPairOfFooAndBar(),
Observable.interval(1, TimeUnit.SECONDS),
BiFunction() {fooBarList: List<Pair<Foo,Bar>>, _:Long -> fooBarList}
).subscribe { fooBarList-> /*....*/ }
我看到了这个答案:https://stackoverflow.com/a/47676208/1461568 但假设第二次调用是可观察到的(我有单次调用)
那该怎么做呢?
【问题讨论】:
标签: rx-java2