2

I have a subscriber that times out in 10 seconds. Where do I pass what happens once the timeout has occurred?

Service.registerUser(registerUserRequest)
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.io())
            .timeout(10, TimeUnit.SECONDS)
            .subscribe(new SingleObserver<RegisterUserResponse>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onSuccess(RegisterUserResponse registerUserResponse) {


                    }
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(LogTags.API, "Error occurred while registering new user.");
                    e.printStackTrace();
                }

            });
2
  • Do you mean you want to detect when time out has occured? Commented Feb 14, 2018 at 21:38
  • 1
    yes that is exactly what I am asking. Commented Feb 15, 2018 at 15:02

1 Answer 1

2

If timeout occurs the onError would be invko TimeoutException so you can check that in onError method with this if:

if( e instanceof TimeoutException)

check this link out : http://reactivex.io/documentation/operators/timeout.html

Sign up to request clarification or add additional context in comments.

1 Comment

Ok! Thank you very much. Let me try it out and I will tell you how it worked out.

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.