Closed
Description
I have UI observable which should work as long as my UI lives. When my UI emits I create a network request which could be an Observable or a Single. A Single fits best for a network call.
RxView.clicks(myButton)
.flatMap(v - > networkRequest())
.subscribe(data -> showSomething(data),
e -> {
// should only be called when the RxView.clicks() throws.
// should not be called for network errors
});
When using an Observable I would use onErrorResumeNext
returning Observable.empty()
to prevent errors coming from the network request going into my UI Observable and calling onError
because the UI Observable should life forever:
Observable networkRequest() {
mApiService.fireActionObservable()
.onErrorResumeNext(throwable -> {
// somehow handle error here
return Observable.empty();
});
}
This, in my opinion, elegant way does not work for Single because no Single.empty()
exists.
Single networkRequest() {
mApiService.fireActionSingle()
.onErrorResumeNext(throwable -> {
// somehow handle error here
return Single.empty(); // <-- does not exist. I have to call success or error :/
});
}
Single.onErrorResumeNext
is btw only available in 2.x
Converting my Single
to an Observable
seems wrong, because the network request is a Single
!