Reputation: 35
Say there is interface containing methods:
Observable<Data> makeHttpCall(int param1, boolean param2);
Completable storeInDatabase(Data data);
Completable combinedCall(int param1, boolean param2);
What is the best way to implement the combinedCall method that would:
Seems that in RxJava 1.0 it was possible to do Completable.merge(Observable) but merge does not seem to accept Observable any more.
Upvotes: 3
Views: 3161
Reputation: 31438
First of all I don't believe merge
is a good fit for your needs, as the storeInDatabase
has to be performed on the results of makeHttpCall
instead of parallel to it.
This should work for you:
Completable combinedCall(int param1, boolean param2) {
return makeHttpCall(param1, param2)
.flatMapCompletable(new Function<Data, CompletableSource>() {
@Override
public CompletableSource apply(@NonNull Data d) throws Exception {
return storeInDatabase(d);
}
});
}
Upvotes: 6