繁体   English   中英

RxJava / RxAndroid + Retrofit,异步进行6个不同的Observable调用

[英]RxJava / RxAndroid + Retrofit , making 6 different Observable calls asyncronous

我正在学习RxJava / Android(目前正在将它与Retrofit结合使用以进行网络调用),现在我有一个问题,说我有6个不同的Observables,例如: Observable<Client> clients = apiInterface.getClients() Observable<Orders> orders = apiInterface.getOrders(); Observable<Products> products = apiInterface.getProducts(); Observable<Client> clients = apiInterface.getClients() Observable<Orders> orders = apiInterface.getOrders(); Observable<Products> products = apiInterface.getProducts();

apiInterface是翻新客户端,而getClients等是调用

现在,我该如何异步执行这6个不同的调用,并且在完成所有6个调用后->做点什么(例如取消进度条)? 当每个调用结束时,我将获得返回调用的数据并通过greenDAO进行插入。 设法将它们同步链接到现在,但是我需要在并行任务中将它们触发(例如我现在对这些调用有6个AsyncTasks + countDownLatch实现)

您应该像这样使用zip运算符:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM