I'm using the new Android persistance lib, Room, with RxJava2. The following code is causing an infinite loop. If I comment out the line that updates the user in the second observable it works fine. If I leave it there, the onNext method of the first observable will be called on and on again.
Does Room requery the table when an entity is updated? If so, why is it publishing the message again on the same stream? Is this intended behavior? Is it a bug in the library?
val userDao = HeyHeyApp.database.userDao();
userDao.getAll()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ listOfUsers ->
if (!listOfUsers.isEmpty()) {
HeyHeyApp.currentUser = listOfUsers.first()
HeyHeyApp.currentUser.fcmDeviceId = getDeviceId()
Single.fromCallable({
HeyHeyApp.database.userDao()
.updateUser(HeyHeyApp.currentUser)
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ _ ->
})
}
})