RxJava zip 3可观察值-onSubscribe滞后

时间:2019-03-27 08:07:31

标签: java rx-java2

请查看以下简单代码:

private void refreshData(String endpoint)
    {
        KProgressHUD busy = Utils.showBusyIndicator(MainActivity.this);
        MCityEndpoint mcityService = ServiceFactory.createRetrofitService(MCityEndpoint.class, Configuration.getApiUrl());

        Disposable disposable = Observable.zip
                (
                        mcityService.getMcityDictionaries(selectedCity.id),
                        mcityService.getEvents(selectedCity.id, endpoint),
                        mcityService.getUserDetails(selectedCity.id),

                        (dictionaries,events, userInfo) ->
                        {
                            processData(dictionaries, events, userInfo);

                            return  events.events;
                        }

                )
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result ->
                {
                    if(mFragment instanceof ListFragment)
                    {
                        ((ListFragment) mFragment).refreshData(result);
                    }

                    updateUserDetails();
                    busy.dismiss();

                    Log.d(Configuration.tag,"Refresh data complete");

                }, throwable ->
                {
                    Log.d(Configuration.tag,throwable.toString());
                    busy.dismiss();
                    this.logout(true);

                });


        mCompositeDisposable.add(disposable);
    }

我想调用3个可观察对象,处理它们的值,最后将数据加载到列表中。可以,但是我迟到了1秒。结果是:

  • 显示繁忙指示器
  • 隐藏繁忙的指示器
  • 1秒延迟,没有可见的忙碌指示器
  • 滞后刷新列表

在这种情况下,我无法理解延迟的原因。一切都应刷新,并且可见繁忙的指示器。你有什么主意吗?

0 个答案:

没有答案