Naman Jain
Naman Jain

Reputation: 361

.timeout with RxJava observer

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();
                }

            });

Upvotes: 2

Views: 2651

Answers (1)

Siavash Abdoli
Siavash Abdoli

Reputation: 1862

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

Upvotes: 2

Related Questions