【发布时间】:2020-05-11 09:47:22
【问题描述】:
我遇到了以下问题: 我有一个 Single 返回一个对象列表,在每个对象内部,有一个字段也是一个 Single,它返回一个项目列表(这是我需要的),但我也需要这个列表返回为一个结果,而不是作为每个单独的..
我有一个可以使用的 Observable,它包装了所有这些代码,所以我想在 onNext 中发出结果。
另外,我还需要将每个 Single 的单独结果添加到缓存中,键为父对象
代码:
object.getListOfObjects().doOnSuccess { objectList ->
objectList.map { singleItemInList ->
singleItemInList.listOfValues.subscribe({ valueList ->
cache[singleItemInList] = valueList
emitter.onNext(valueList)
// ^ this is the bit where i need to get all values instead of
// emitting on next for each item
},{
emitter.onError(it)
})
}
}.subscribe( {
/* no-op*/
}, {
emitter.onError(it)
})
任何帮助将不胜感激!
提前谢谢:)
编辑 - 额外细节:
fun getListOfObjects(): Single<List<Object>> =
Single.zip(
allObjects().map { it.objects() }
) { t: Array<Any> ->
t.map { it as Object }
}
Object {
[...]
val listOfValues: Single<ValueList>
[...]
}
【问题讨论】:
标签: android rx-java rx-java2 rx-android