How to check whether the data in the database using rxjava2?

Have a method that returns Flowable<List<Item>>. Due to take(1) we get a list, but no longer receive the updates from the database. If it is clear and in the database will have no records, then the list will not eventually return.

How can I check if a DB record and in the absence of receive data from the server and then return the local list?

fun loadItems(forceRemote: Boolean): Flowable<List<Item>> {
return if (forceRemote) {
 } else {
 itemDataSource.loadLocalItems().take(1).filter { !it.isEmpty() }.switchIfEmpty(loadRemoteData())

private fun loadRemoteData(): Flowable<List<Item>> {
 return itemDataSource.loadRemoteItems().switchMap {
itemsDataSource.addItems(it).and then(itemDataSource.loadLocalItems())
March 19th 20 at 08:53
1 answer
March 19th 20 at 08:55
The database should give an empty list if no data. Further on the void list triggering a trip to the server.

Find more questions by tags Kotlin