0

I need to write subsequent requests in my Android project. So first an API request is made and when the asynchronous response comes back, the response are used in the second request, and so on.

I've been studying the RxJava2 library but I haven't comprehended fully yet. Furthermore, the RxJava code will be in an Interactor class, that will call functions that reside in a repository, so I don't want to write out code directly inside the RxJava2 code, but call functions from another class. A GitHub repo that cover these areas would be very useful for me.

3
  • Have you looked at the flatMap operator? Commented Jan 15, 2018 at 7:55
  • Just read some about it, but I can't see right away how that'll help me. Some real examples would be very helpful. Commented Jan 15, 2018 at 8:50
  • You can see some examples of flatMap here github.com/politrons/reactive/blob/master/src/test/java/rx/… Commented Jan 15, 2018 at 11:38

1 Answer 1

3

The flatMap operator is a canonical way for specifying continuations that depend on the result(s) of a previous source(s):

retrofitAPI.getData(params)
.flatMap(data -> 
     retrofitAPI.getMoreData(data)
     .flatMap(moreData -> retrofitAPI.getEvenMoreData(data, moreData))
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Just the kind of answer I was hoping for, will definitely test this.

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.