rx-javarx-java2reactivex

RxJava - create a sequence from two Single observable


I have two Singles:

  1. fetching user information data from Facebook.
  2. perform user registration on my server with the information fetched from Facebook.

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?


Solution

  • Try flatMap:

    fetchUser
        .flatMap(user -> registerUser(user)) // .flatMap(this::registerUser)
        .subscribe()
    
    
    public Single<User> fetchUser() {...}
    public Single<?> registerUser (User user) {...}