I faced very strange issue and have no idea why it is happening. When I have stream with fromIterable to insert to Room items one by one, it does not insert. No exceptions, nothing. I even put breakpoint to generated Room DAO implementation class, it call method but does not go inside Completable block, just ignoring it.
repository.insert(mapper.transform(item))
.flatMap { id ->
Observable.fromIterable(item.tags)
.map { tag ->
anotherRepository.insert(
JoinEntity(id, tag.id)
)
}
.toList()
.flatMap { Single.just(id) }
}
But if I will remove fromIterable, and replace with direct insert call, it does work and it inserts normally. Without any other changes.
repository.insert(mapper.transform(item))
.flatMap { id ->
anotherRepository.insert(JoinEntity(1, 1))
.andThen(Single.just(id))
}
I tried so many things already and still have no ideas. Tried flattenAsFlowable
, also does not work.
Will appreciate any help. Thanks!
Okey, found out the issue, maybe will help somebody.
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) }
}
I've changed map/flatMap
to flatMapSingle
, so its actually being emitted.