These are chat archives for ReactiveX/RxJava

24th
Aug 2018
Igor Bozin
@igorbzin_gitlab
Aug 24 2018 14:46

@akarnokd yes, something exactly like this, thank you. I am still not sure how to chain those asynchronous calls though, since i operate on the database.

        Observable.just(uriObservableList)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<RxObservableList<Uri>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        Log.d(TAG, "ONSUBSCRIBE ");
                    }

                    @Override
                    public void onNext(RxObservableList<Uri> uris) {
                        String s = makePathString(uris.getList());
                        AppExecutor.getInstance().diskIO().execute(() -> viewModel.updatePicturePaths(s)); // <-- THis async call should be performed on every onNext 
                        mAdapter.updatePictures(uris.getList());
                        Log.d(TAG, "ONNEXT");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "ONERROR  " + e);
                    }

                    @Override
                    public void onComplete() {
                        Log.d(TAG, "ONCOMPLETE  ");
                    }
                });

How do I construct my Subscription so that before every onNext call I can perform a write operation on the database? I have tried doOnNext which is supposed to be executed before onNext, but it is always called from the main thread

David Stocking
@dmstocking
Aug 24 2018 19:33
@ylecaillez woopsy I didn't notice your message. Yours appears to be really similar. The only difference appears to be that I take a action to run not just filter the first value. Yours kind of looks like it implements first().