0

I am trying to authorize in two services in parallel, but each of them has two steps:

The first service

1) Log in account if the user exist (else create account)

2) Create account if the user doesn't

 Maybe<String> login()
 Maybe<String> create() 

The second service has the same steps.

 Maybe<Result> login2()
 Maybe<Result> create2()

I know that i can use ZIP operator for parallel requests, but i can't understand how to do all this scheme. What is the right way? I am using RxJava2 + Retrofit2.

1 Answer 1

1

You should be able to use something like following for the login/create sequencing:

Maybe.concat(login, create).firstElement();

(and can then use zip, as you mentioned, to parallelize doing this for the 2 services)

The following is a good article that covers both these patterns https://medium.com/devnibbles/rxjava-the-first-3-patterns-4c112a85b689

Sign up to request clarification or add additional context in comments.

2 Comments

John, thank you for answer and article. Now I am trying to use flatmap instead of concat, I can't understand the difference.
@Delphian with flatMap you will end trying to create an already created account

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.