In the android app, the process goes like that: at first, I fetch notes from local SQLite and then make Http calls for each note. I use composite disposable to hold all disposables and release them when activity is destroyed. The code looks something like that:
class MyActivity : AppCompatActivity(){
var compositeDisposable = CompositeDisposable()
override fun onResume(){
updateDatabaseData()
}
fun updateDatabaseData(){
compositeDisposable.add(
Observable.fromCallable{
fetchDataFromDatabase()
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap{
Observable.fromIterable(it)
}
.flatMap{
getUpdateStateObservable(it) // make remote HTTP call for every note in the list from local DB
}
.subscribe()
)
}
fun getUpdateStateObservable(note:Note):UpdatedNote{
Observable.fromCallable(
// make HTTP call and build some UpdatedNote
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
fun fetchDataFromDatabase():List<Note>{
// fetch data from local DB
}
}
And this code worked well until the moment when internet connection is lost. So every time HTTP calls in method getUpdateStateObservable
is made an error is thrown. And sometimes it results in io.reactivex.exceptions.UndeliverableException
pointing at line where network error in getUpdateStateObservable
happens. And sometimes it's not. I've tried to use not a pool of threads but a single one as Schedulers.single()
when making the HTTP request. And this works well. However, I'd like to process all those requests concurrently to speed them up.
Thanks