I am using Room
and RxJava2
in Android application. I have a scenario inwhich I want to same function to run synchronously
at some point and to run asynchronously
on other place. Below is the function:
@Query("SELECT * from saved_survey WHERE enumeratorId = :enumeratorId and isDeleted=:isDeleted ORDER BY savedSurveyTime DESC")
fun getSavedSurveyList(enumeratorId: String, isDeleted: Boolean): Flowable<List<SavedSurvey>>
I want to run this function synchronously when called from IntentService
and run asynchronously when called from UI thread. I am calling this function as:
savedSurveyViewModel.getSavedSurveyList(enumeratorId, false)
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe()
I dont want to make multiple functions in repository
or viewmodel
. Any efficient approach will be appreciated.
Thanks