我面对一个非常奇怪的问题,不知道为什么会这样。当我具有fromIterable的流以一一插入到Room项目时,它不会插入。没有例外,没有。我什至在生成的Room DAO实现类中添加了断点,它调用方法,但没有进入Completable块,只是忽略了它。
repository.insert(mapper.transform(item))
.flatMap { id ->
Observable.fromIterable(item.tags)
.map { tag ->
anotherRepository.insert(
JoinEntity(id, tag.id)
)
}
.toList()
.flatMap { Single.just(id) }
}
但是如果我要从fromIterable中删除,并替换为直接插入调用,它将起作用并且可以正常插入。没有任何其他更改。
repository.insert(mapper.transform(item))
.flatMap { id ->
anotherRepository.insert(JoinEntity(1, 1))
.andThen(Single.just(id))
}
我已经尝试了很多事情,但仍然没有想法。尝试过flattenAsFlowable
,也无效。
将不胜感激。谢谢!
Okey,发现了问题,也许会对某人有所帮助。
repository.insert(mapper.transform(item))
.flatMap { id ->
Observable.fromIterable(item.tags)
.filter { tag -> tag.id != null }
.flatMapSingle { tag -> anotherRepository.insert(JoinEntity(id, tag.id)) }
.toList()
.flatMap { Single.just(id) }
}
我将map/flatMap
更改为flatMapSingle
,因此它实际上已发出。