Reputation: 15117
I am currently using:
PublishSubject<PubNubObserverData> = PublishSubject.create()
I was wondering how I can restart the subscription when
onError(Throwable e)
is called by?
Currently the subscription stops when there is an error.
Upvotes: 0
Views: 406
Reputation: 8227
You can use retry()
operator to automatically re-subscribe immediately. Alternatively, you can use retryWhen()
operator to resubscribe after a delay or only conditionally.
observable
.retryWhen( error -> error.flatMap( e -> Observable.timer(1, SECONDS))
will retry the subscription after 1 second. Using flatMap()
you could also test the kind of error and only retry on a particular error.
observable
.retryWhen( error -> error.flatMap( e -> {
if (e instanceof IOException) {return Observable.timer(1, SECONDS);}
return Observable.just( e );
} )
will retry if the error is IOException
and not for any other type of error.
Upvotes: 2