Closed thealmikey closed 5 years ago
I found out the solution to my problem, in my RoomPersister in the write
method i was passing blogLocalService.addBlogs(blogList)
which returns a Single<List<Blog>>
. This is what i had previously
val persister = object : RoomPersister<List<Blog>, List<Blog>, BarCode> {
override fun read(barCode: BarCode): Observable<List<Blog>> {
return blogLocalService.fetchAll().toObservable()
}
override fun write(barCode: BarCode, blogList: List<Blog>) {
blogLocalService.addBlogs(blogList)
}
}
I wrongly assumed that the Singe<List<Blog>>>
method would somehow automatically get subscribbed to. This was my final code that worked
val persister = object : RoomPersister<List<Blog>, List<Blog>, BarCode> {
override fun read(barCode: BarCode): Observable<List<Blog>> {
return blogLocalService.fetchAll().toObservable()
}
override fun write(barCode: BarCode, blogList: List<Blog>) {
blogLocalService.addBlogs(blogList).
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe({
Log.d("BlogLocalService","successful write to db")
},{
Log.d("BlogLocalService","failed to write to db with error: ${it.message}")
})
}
}
Hi guys, I'm having an issue where my code which hits an API endpoint successfully from the fetcher doesn't update the persister. I'm using Android Room with StoreRoom
calls to getBlogs() above don't get data from the server, only fetch data locally stored ,whereas calls to blogRemoteService.fetchBlogs() in my Fetcher successfully return
Single<List<Blog>>
,