I have a question.
I need to get list of some items by a list of the item ids. At first, I tried
Observable.from(itemIds)
.flatMap(itemId -> requestToServer(itemId))
.subscribe(item -> { /* do something */ });
But the operator flatMap
does not guarantee the order of items.
I need to get item in order that ItemIds
have.
It would be great if there was the api like Promise.all()
.
Is there a way like Promise.all()
in RxJava? or any other ways?
Use concatMap instead. That will concatenate the emitted Observables in order rather than merging their emissions
It sounds like you're looking for the Zip operator
For example:
prints:
1 Blah true