问题
Hi There I am new in RxJava I am trying to call two API sequential the result of one api used as input to other and lastly return value of second app
Currently I am trying with below code
public Single<List<LocationParcelableItem>> getUpdateRecentLocation(
LocationViewType locationViewType, Map<String, String[]> filter) {
return locationRepository
.getRecentLocations(filter)
.subscribeOn(Schedulers.io())
.flatMapMaybe(this::updateRecentLocationList)
.flatMapSingle(userLocationParcelableItem -> getRecentLocations(locationViewType));
}
scenario is like I want updated location always even it is stored in local DB below are the steps that I want to perform
getSavedRecord
from Database( locationRepository .getRecentLocations(filter) )- return
Single<List<RecentLocationRecord>>
- return
collect Ids from above list then call API to get Updated List
(.flatMapMaybe(this::updateRecentLocationList))
- if record found from step 1 then update database record if not then delete database record
- get updated record from Database (same as step 1 -
flatMapSingle(userLocationParcelableItem -> getRecentLocations(locationViewType))
)
below is working well just thing is when compiler comes to .flatMapMaybe(this::updateRecentLocationList)
it doesn't execute code inside method of updateRecentLocationList
it directly jump to next flat map as flatMapSingle
and same happen there then return without waiting for result. After getUpdateRecentLocation
return then updateRecentLocationList
is executed
I want flatMap wait for other flatmap to complete and return the result of last faltMap
来源:https://stackoverflow.com/questions/58994906/how-to-perform-multiple-api-call-synchronously-or-call-api-sequentially-using-rx