restartableLatestCache with combined Observables
pedrofg opened this issue · 4 comments
Hi, i'm trying to use the method restartableLatestCache() returning in the frist parameter a combined Observable which we can create using the method Observable.zip, as follow:
final Observable<MovieDetail> movieDetailsObservable = App.getServerApi().getMovieDetail(movieId)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
final Observable<MovieDetail>movieImagesObservable =App.getServerApi().getMovieImages(movieId)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
final Observable<MovieDetail> combined = Observable.zip(movieDetailsObservable, movieImagesObservable, new Func2<MovieDetail, MovieDetail, MovieDetail>() {
@Override
public MovieDetail call(MovieDetail movieDetail, MovieDetail movieImage) {
movieDetail.setBackdrops(movieImage.getBackdrops());
movieDetail.setPosters(movieImage.getPosters());
return movieDetail;
}
});
restartableLatestCache(REQUEST_MOVIE_DETAIL,
new Func0<Observable<MovieDetail>>() {
@Override
public Observable<MovieDetail> call() {
return combined;
}
},
new Action2<MovieDetailActivity, MovieDetail>() {
@Override
public void call(MovieDetailActivity activity, final MovieDetail response) {
activity.fillMovieDetails(response);
}
},
new Action2<MovieDetailActivity, Throwable>() {
@Override
public void call(MovieDetailActivity activity, Throwable throwable) {
//TODO handle error
}
});
When this code executes nothing happens, there is no result, the callbacks are not called. But if i execute directly using "subscribe", it works, as follow:
combined.subscribe(new Subscriber<MovieDetail>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(MovieDetail movieDetail) {
getView().fillMovieDetails(movieDetail);
}
});
Do you have any idea why it is not working? Is it a bug from nucleus api?
You need to call start(REQUEST_MOVIE_DETAIL)
at some point
I have the start called, i just didn't put this part of code. the method restartableLatestCache actually return a http 404. But when i execute using .subscribe as shown in the code it works well.
I see no way Nucleus can be connected with http 404. It just connects observables with views, it does not change observables itself. It also does not send any information to your server.
What you mean? is it not weird when i execute via restartable() returns a 404 and when i execute via rxjava it returns ok? Could you test it in some of your projects?