1

Let's say that I have 'n' data sources (REST APIs for instance):

Observable<List<DataItem>> source1 = api.source1();
Observable<List<DataItem>> source2 = api.source2();
Observable<List<DataItem>> source3 = api.source3();
...
Observable<List<DataItem>> sourcen = api.sourcen();

where 'n' is relatively small (~10)

What I want to do is to take all those sources, run them in parallel and receive List<DataItem> list containing all DataItems from all observables, but only when every network call is finished.

Thanks in advance

Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42
pawelo
  • 1,405
  • 4
  • 15
  • 30

1 Answers1

2

Can do something like:

List<Observable<?>> obsList = Arrays.asList(source1, source2, source3, ...);

Observable.zip(obsList, ...
John O'Reilly
  • 10,000
  • 4
  • 41
  • 63
  • The suggestion I've seen to do this is to use something like: `Observable> source1 = api.source1().subscribeOn(Schedulers.newThread());` etc (from http://stackoverflow.com/questions/38234152/how-can-i-make-this-rxjava-zip-to-run-in-parallel) – John O'Reilly Dec 10 '16 at 13:31
  • Works like a charm. Thanks! – pawelo Dec 10 '16 at 14:25