Nilzor
Nilzor

Reputation: 18593

How can I perform an ordered merge with RxJava?

I'm performing 3 HTTP requests. I want to fire all simultaneously, wait for all to complete, then merge the three requests while preserving the order of the sequence. Let's say I have the requests r1, r2 and r3 and I want to process the results in that order. I've attempted this:

Observable<HttpResponse> r1, r2, r3;
Observable<List<HttpResponse>> merged = Observable.merge(r1, r2, r3).buffer(3);

In this case there is no guarantee that r3 is index 2 in the returned list. Suggestions?

Upvotes: 4

Views: 363

Answers (1)

akarnokd
akarnokd

Reputation: 70007

The current RxJava snapshot contains a concatMapEager that will run its sources immediately and join them one after the other. It will be part of 1.0.15 but I don't know when Netflix will release it. If you don't want to depend on a snapshot then take the source code and lift it manually into your sequence.

Upvotes: 3

Related Questions