0
final List<Order> orders = Observable
            .from(searchAttributes)
            .filter(searchAttribute-> !searchAttribute.isEmpty())
            .flatMap(searchAttribute-> Observable.just(networkCall(searchAttribute)).subscribeOn(Schedulers.io()))
            .toList()
            .toBlocking()
            .single();

I am using the following article to learn RxJava : https://proandroiddev.com/understanding-rxjava-subscribeon-and-observeon-744b0c6a41ea

In the above code networkCall function should happen on a separate IO thread however the network call happens on the same IO thread basically sequentially. How do I parallelize the call using RxJava?

humbleCoder
  • 667
  • 14
  • 27

1 Answers1

0

With RxJava 2 can use .parallel.

From this answer:

Flowable<Integer> vals = Flowable.range(1, 10);

vals.parallel()
        .runOn(Schedulers.computation())
        .map(i -> intenseCalculation(i))
        .sequential()
        .subscribe(val -> System.out.println(val));

gpunto
  • 2,573
  • 1
  • 14
  • 17
  • We are already using older RxJava because of couchbase hence cant use this however thats for the info. – humbleCoder Mar 18 '19 at 07:13
  • With rxjava1 you have to do . subscribeOn inside the flatmap too. If you take a look at the answer I linked, this solution is proposed too – gpunto Mar 18 '19 at 07:37