Given the following chain:
public Observable<List<PoiCollection>> findPoiCollectionsByUserId(Integer userId) {
return findUserGroupsByUserId(userId)
.flatMapIterable(
userGroups -> userGroups)
.flatMap(
userGroup -> findPoiCollectionToUserGroupsByUserGroupId(userGroup.getId()))
.flatMapIterable
(poiCollectionToUserGroups -> poiCollectionToUserGroups)
.flatMap(
poiCollectionToUserGroup -> {
Observable<PoiCollection> poiCollectionById = findPoiCollectionById(poiCollectionToUserGroup.getPoiCollectionId());
return poiCollectionById;
})
.toList()
.doOnNext(poiCollections -> {
Timber.d("poi-collections from DB:", poiCollections);
for(PoiCollection collection : poiCollections) {
Timber.d("collection:", collection);
}
})
.doOnError(throwable ->
Timber.e("error fetching poi-collections for user from DB"));
}
Which is invoked like this:
Observable<List<PoiCollection>> fromDB = databaseHelper.findPoiCollectionsByUserId(id);
fromDB.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
poiCollections -> {
Activity activity = (Activity) getView();
Intent intent = new Intent(activity, PoiCollectionsActivity.class);
intent.putExtra("poi_collections", (Serializable) poiCollections);
activity.startActivity(intent);
activity.finish();
},
throwable -> {
if (throwable instanceof SocketTimeoutException) {
getView().showInternetDialog();
}
});
I find myself wondering why neither doOnNext(...)
nor doOnError(...)
is being invoked. The chain is being executed until toList()
, thus the below lines are being executed, it just stops afterwards.
poiCollectionToUserGroup -> {
Observable<PoiCollection> poiCollectionById = findPoiCollectionById(poiCollectionToUserGroup.getPoiCollectionId());
return poiCollectionById;
})
A breakpoint at poiCollectionById
and another one inside findPoiCollectionById(...)
clearly show, the result is being fetched from DB successfully!
So, what's preventing doOnNext(...)
from being called? I clearly invoke subscribe(...)
on the observable. The mapping chain runs until toList()
. I never see the code run into doOnError(...)
, nor do I ever run into the Action<Throwable>
part of subscribe(...)
. Must have something to do with toList()
.