[英]How to get emitted value from first observable
I have a flow like this 我有这样的流程
Observable.fromIterable(configuration.symbols) // list of data (for ex. 0, 1, 2, 3)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.flatMap {
api.anotherCall(
symbol = it) // emitted value
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
}
.subscribe { res ->
{
Ln.i(res) // result, but it would be perfect to know this data + symbol as a second param
}
}
Thanks for any help 谢谢你的帮助
ps Kotlin syntax ps Kotlin语法
You have to use something else than flatMap
like zip
( doc ). 除了像zip
( doc )这样的flatMap
之外,你还必须使用其他东西。
With zip
the two observable will be combined two by two. 使用zip
,两个可观察量将两个一个组合。
Or you can continue to use flatMap
but add a map
on the second observable like: 或者您可以继续使用flatMap
但在第二个observable上添加一个map
,如:
api.anotherCall(symbol = it) // emitted value
.map { secondValue -> it to secondValue }
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
Then the end observer will receive a Pair<>
. 然后结束观察者将收到一Pair<>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.