Reputation: 502
I have two Singles:
I want the second Single to start right after the first one called onSuccess, the second Single depends on the data from the first. I'm looking for the right operator to achieve this. any recommendation?
Upvotes: 2
Views: 1461
Reputation: 3040
Try flatMap:
fetchUser
.flatMap(user -> registerUser(user)) // .flatMap(this::registerUser)
.subscribe()
public Single<User> fetchUser() {...}
public Single<?> registerUser (User user) {...}
Upvotes: 3
Reputation: 1039
Other way to do it with zip
public Single<List<DataEntry>> getting(String rawSearchText) {
Single single1 = dbSearch(rawSearchText);
Single single2 = onlineSearch(rawSearchText);
return Single.zip(single1, single2, (b1, b2) -> CombineTwoLists(b1, b2))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
Upvotes: -1