0

I have many request merged in Observable, and I need a Timeout Not for every emission but for complete observable in RXjava. Is it Possible??

            Observable
            .merge(listOfObservables).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<Response>() {

                @Override
                public void onNext(@io.reactivex.annotations.NonNull Response response) {
                    
                }

                @Override
                public void onError(@io.reactivex.annotations.NonNull Throwable e) {
                  
                }

                @Override
                public void onComplete() {
                  
                }
            });

1 Answer 1

1

You could use takeUntil with a delayed error:

Observable
.merge(listOfObservables)
.subscribeOn(Schedulers.io())
.takeUntil(Observable.error(new TimeoutException()).delay(5, TimeUnit.MINUTES, true))
.observeOn(AndroidSchedulers.mainThread())
Sign up to request clarification or add additional context in comments.

3 Comments

It relays your sequence of items until the given other sequence, in this case a delayed error signal of TimeoutException, happens. This stops the merge and your onError will be called.
It means an Error observable starts running parallel to my merged observables, if my merged observables not completed within 5 minutes takeUnitl will throw error and ignore remaining observables right??
Thanks, its working, i learned a new Logic in RxJava Today

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.