Romain
Romain

Reputation: 1410

Call void method and pass trought arguments RxJava

I'm looking for a better to do this :

mRestService.login(email, password) // Login user in
                .flatMap(user -> Observable.zip(
                        mRestService.start(user._token), // Start his session
                        Observable.just(user),
                        (v, u) -> (User) u // Pass user throught
                ))
                .subscribe(user -> {
                }, throwable -> {                     
                });

But I coudn't come up with something better.

Upvotes: 0

Views: 764

Answers (2)

dwursteisen
dwursteisen

Reputation: 11515

the start method on the mRestService perform a side effect. So you can use doOnNext method which is here for this sort of side effect.

 mRerstService.login(email, password)
              .doOnNext(u -> mRestService.start(user._token))
              .subscribe(); 

Upvotes: 1

Ilya Ghirici
Ilya Ghirici

Reputation: 13

You should call mRestService.start(user._token) in flatMap. The user object will be passed to subscribe where you can use it.

 mRestService.login(email, password) // Login user in
                .flatMap((user -> mRestService.start(user._token)))
                .subscribe(user -> {
                }, throwable -> {
                });

Upvotes: 0

Related Questions