Created
March 23, 2015 13:50
-
-
Save cavega/7fea2c3160a4a6324794 to your computer and use it in GitHub Desktop.
Use RXJava for Merging Response of 2 API calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.combineLatest( | |
ApiProvider.requestSource1(param1), | |
ApiProvider.requestSource2(param2), | |
this::combinedResponses) | |
.map(responseObject -> saveResponse(responseObject, context)) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(responseObject -> onResponseReceived(responseObject, listener), | |
null != errorCallback ? errorCallback : this::onFetchObjectFailed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The 2 responses are different. In my example, I'm sending the response "responseObject" from "source 1" into the map so that it can be used by the callback of "source 2" once the latter returns successfully. My use case was that I needed to merge the 2nd response with the results of the first 1 into a single object.