1

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

Muhammad Farhan
  • 1,113
  • 10
  • 22
  • did you checked this ? https://stackoverflow.com/questions/43884764/undeliverableexception-while-calling-onerror-of-observableemitter-in-rxjava2 – Nour Eldien Mohamed Feb 14 '20 at 13:18
  • That's not what I'm looking for. I understand that inside ```getUpdateStateObservable``` every HTTP call results in Exception. The issue is when those Exceptions happen concurrently (see ```subscribeOn(Schedulers.io())```) that results in UndeliverableException. But when i switch to processing requests sequentally as ```Schedulers.single()``` that works good. Why is that? – Allison Catcher Feb 15 '20 at 07:16

0 Answers0