{"id":7953,"date":"2015-11-12T03:16:47","date_gmt":"2015-11-12T03:16:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/12\/rxjava-fetching-observables-in-parallel-open-source-projects-reactivex-rxjava\/"},"modified":"2015-11-12T03:16:47","modified_gmt":"2015-11-12T03:16:47","slug":"rxjava-fetching-observables-in-parallel-open-source-projects-reactivex-rxjava","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/12\/rxjava-fetching-observables-in-parallel-open-source-projects-reactivex-rxjava\/","title":{"rendered":"RxJava Fetching Observables In Parallel-open source projects ReactiveX\/RxJava"},"content":{"rendered":"<p>The parallel operator proved to be a problem for almost all use cases and does not do what most expect from it, so it was removed in the 1.0.0.rc.4 release: https:\/\/github.com\/ReactiveX\/RxJava\/pull\/1716<\/p>\n<p>A good example of how to do this type of behavior and get parallel execution can be seen here.<\/p>\n<p>In your example code it is unclear if <code>searchServiceClient<\/code> is synchronous or asynchronous. It affects how to solve the problem slightly as if it is already async no extra scheduling is needed. If synchronous extra scheduling is needed.<\/p>\n<p>First here are some simple examples showing synchronous and asynchronous behavior:<\/p>\n<pre><code>import rx.Observable;\nimport rx.Subscriber;\nimport rx.schedulers.Schedulers;\n\npublic class ParallelExecution {\n\n    public static void main(String[] args) {\n        System.out.println(\"------------ mergingAsync\");\n        mergingAsync();\n        System.out.println(\"------------ mergingSync\");\n        mergingSync();\n        System.out.println(\"------------ mergingSyncMadeAsync\");\n        mergingSyncMadeAsync();\n        System.out.println(\"------------ flatMapExampleSync\");\n        flatMapExampleSync();\n        System.out.println(\"------------ flatMapExampleAsync\");\n        flatMapExampleAsync();\n        System.out.println(\"------------\");\n    }\n\n    private static void mergingAsync() {\n        Observable.merge(getDataAsync(1), getDataAsync(2)).toBlocking().forEach(System.out::println);\n    }\n\n    private static void mergingSync() {\n        \/\/ here you'll see the delay as each is executed synchronously\n        Observable.merge(getDataSync(1), getDataSync(2)).toBlocking().forEach(System.out::println);\n    }\n\n    private static void mergingSyncMadeAsync() {\n        \/\/ if you have something synchronous and want to make it async, you can schedule it like this\n        \/\/ so here we see both executed concurrently\n        Observable.merge(getDataSync(1).subscribeOn(Schedulers.io()), getDataSync(2).subscribeOn(Schedulers.io())).toBlocking().forEach(System.out::println);\n    }\n\n    private static void flatMapExampleAsync() {\n        Observable.range(0, 5).flatMap(i -&gt; {\n            return getDataAsync(i);\n        }).toBlocking().forEach(System.out::println);\n    }\n\n    private static void flatMapExampleSync() {\n        Observable.range(0, 5).flatMap(i -&gt; {\n            return getDataSync(i);\n        }).toBlocking().forEach(System.out::println);\n    }\n\n    \/\/ artificial representations of IO work\n    static Observable getDataAsync(int i) {\n        return getDataSync(i).subscribeOn(Schedulers.io());\n    }\n\n    static Observable getDataSync(int i) {\n        return Observable.create((Subscriber<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The parallel operator proved to be a problem for almost all use cases and does not do what most expect from it, so it was removed in the 1.0.0.rc.4 release: https:\/\/github.com\/ReactiveX\/RxJava\/pull\/1716 A good example of how to do this type of behavior and get parallel execution can be seen here. In your example code it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7953","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7953"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7953\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}