Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

java - How do I properly/efficiently merge observables?

I'm using Observable.combineLatestDelayError to combine observables, in my case, PublishSubjects, to process data received from multiple network sources.

Disposable disUserAccounts = Observable.combineLatestDelayError(Arrays.asList(userAccountsSub,
            btcUserListSub, btcUserSub, productsSub, instrumentsSub, userInfoSub,
            configSub, configProductSub, configLevel1Sub, btcConfigSub),
            observer -> {
                List<Integer> accountIds = new ArrayList<>();
                String userAccounts = (String) observer[0];
                BtcUserListResponse btcListResponse = (BtcUserListResponse) observer[1];
                UserResponse btcUserResponse = (UserResponse) observer[2];
                String products = (String) observer[3];
                String instruments = (String) observer[4];
                String userInfoRaw = (String) observer[5];

                //save values to shared preferences

                return accountIds;
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(accounts -> {

               //update UI

            }, error -> {
                Toast.makeText(this, "Failed retrieving accounts, products," +
                        " and instruments.", Toast.LENGTH_SHORT).show();
            });

However, after I receive all values and start aggregating them, the UI stutters a bit. I'm showing a progress bar while waiting and processing the values. I tried subscribing and/or observing the observable to Schedulers.io() but it seems like the combiner still runs on the UI thread. Emitting subjects' .onNext(value) on either UI thread or background thread makes no difference either. So, how do I properly combine all my subjects outside the UI thread?

question from:https://stackoverflow.com/questions/65847042/how-do-i-properly-efficiently-merge-observables

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...