2017-07-01 68 views
0

我在学习RxJava /安卓(我目前它改造为网络电话相结合),现在我有一个问题的过程中说,我有6个不同的观测,像这样: Observable<Client> clients = apiInterface.getClients() Observable<Orders> orders = apiInterface.getOrders(); Observable<Products> products = apiInterface.getProducts();RxJava/RxAndroid +改造,使6级不同的可观察到的呼叫asyncronous

等 apiInterface作为改造的客户端,并getClients等作为来电

现在,我该怎么办,这些6个不同的电话asyncronous,当所有6完成 - >做点什么(比如dimiss进度条)? 当每个通话结束时,我会得到数据返回通话并通过greenDAO插入。设法链他们syncronously到现在为止,但我需要他们在并行任务(如6个AsyncTasks + countDownLatch实现我现在所拥有的这些调用)

+0

不是机器人,但也许[这将有助于(https://stackoverflow.com/questions/39214073/rxjava-instead-of-asynctask/39215031#39215031) –

回答

2

您应该使用压缩运营商一样,被解雇:

Observable<Client> clients = apiInterface.getClients() 
Observable<Orders> orders = apiInterface.getOrders(); 
Observable<Products> products = apiInterface.getProducts(); 

Observable<String> clientorders = Observable.zip(
         clients, 
         orders, 
         products, 
         new Func3<Client, Orders, Products> { 
           @Override 
           public String call(Client client, Orders orders, products products) { 


             return "progress bar dismissed" ; 
           } 
         } 
);  

clientorders.subscribe(new Action1<String>() { 

        @Override 
        public void call(String s) { 
         //action 
         //dimiss progress bar 
        } 

       }) 
} 

邮编操作:http://reactivex.io/documentation/operators/zip.html

+0

非常感谢,我会尽力,明天和标记答案是正确的,如果我有一些成功 – Alex

+1

谢谢,它的工作原理,操作应该是一个新的观察员,对于那些谁可以读这篇文章,不知道它应该是什么,FUNC3实际上是对RxAndroid功能3(或4,5等)顺便说一句, – Alex