Main POJO:
class VideoResponse{
List<VideoFiles> videosFiles;
}
I have the following case where i combine the results from two database operation and return as Observable(List(VideoResponse)) .
##Update##
mDbHelper
===/* getVideoCategory() returns Observable<List<VideoResponse>> */=========
.getVideoCategory()
.flatMapIterable(videoResponses -> videoResponses)
.doOnNext(videoResponse -> {
Timber.d("Flatmap Iterable Thread == > %s", Thread.currentThread().getName());})
.concatMap((Function<VideoResponse, ObservableSource<VideoResponse>>) videoResponse -> {
Integer videoId = videoResponse.getId();
return Observable.fromCallable(() -> videoResponse)
.doOnNext(videoResponse1 -> {
Timber.d("Thread before ZIP WITH ===>
%s", Thread.currentThread().getName());
})
===/* getVideoFileList(int videoId) returns Observable<List<VideoFiles>> */====
.zipWith(getVideoFilesList(videoId)),
(videoResponse1, videoFiles) -> {
videoResponse1.setFiles(videoFiles);
return videoResponse1;
})
.doOnNext(vResponse -> {
Timber.d("Thread After ZIP WITH ===>
%s",Thread.currentThread().getName());
})
======= /*This Gets printed*/ ======================
.doOnComplete(()->{
Timber.d(" OnComplete Thread for Video Files ===> %s ",Thread.currentThread().getName());
});
})
.toList()
.toObservable()
===/* Below Print statement is not getting Executed */=================
.doOnComplete(()->{
Timber.d(" Thread doOnComplete");
})
.doOnNext(videoResponses -> {
Timber.d("Thread after loading from the LOCAL DB ====> %s", Thread.currentThread().getName());
});
Below are the scheduler threads being executed:
Flatmap Iterable Thread == > RxCachedThreadScheduler-1
Thread before ZIP WITH ===> RxCachedThreadScheduler-1
Flatmap Iterable Thread == > RxCachedThreadScheduler-1
Thread After ZIP WITH ===> RxCachedThreadScheduler-2
Thread before ZIP WITH ===> RxCachedThreadScheduler-2
Thread After ZIP WITH ===> RxCachedThreadScheduler-2
The final onNext is never getting executed.I need to return the List in the OnNext. I have placed observeOn on different positions ,nothing seems to work..!! Any suggestions..
##Update## Using SqlBrite,
@Override
public Observable<List<VideoResponse>> getVideoCategory() {
return mDBHelper
.createQuery(VideoEntry.TABLE_NAME,
DbUtils.getSelectAllQuery(VideoEntry.TABLE_NAME))
.mapToOne(DbUtils::videosFromCursor);
@Override
public Observable<List<VideoFiles>> getVideoFilesList(int videoId) {
return mDBHelper.createQuery(VideoDetailsEntry.TABLE_NAME,
DbUtils.getSelectFromId(VideoDetailsEntry.TABLE_NAME,VideoDetailsEntry.COLUMN_VIDEO_ID),
String.valueOf(videoId))
.mapToOne(DbUtils::videoDetailsFromCursor);
}
As hinted by @BobDalgleish , the OnComplete was being called before the toList instead of after ZipWith .Now i have made the following changes , and i get as complete list from db. I have used concatMap for preserving the order and wait for complettion.
I know this looks kind of messy !!.any suggestion or optimizations , do kindly post..!!