0
鑑於以下鏈:doOnNext()從來沒有所謂的
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"));
}
被調用是這樣的:
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();
}
});
,我發現自己不知道爲什麼沒有doOnNext(...)
也不doOnError(...)
被調用。鏈正在執行,直到toList()
,因此下面的行被執行,之後它才停止。
poiCollectionToUserGroup -> {
Observable<PoiCollection> poiCollectionById = findPoiCollectionById(poiCollectionToUserGroup.getPoiCollectionId());
return poiCollectionById;
})
斷點在poiCollectionById
,並從DB順利另一個內部findPoiCollectionById(...)
清楚地表明,其結果,正在獲取!
那麼,什麼能阻止doOnNext(...)
被調用?我明確調用subscribe(...)
上的可觀察。映射鏈運行至toList()
。我從來沒有看到代碼運行到doOnError(...)
,我也沒有碰到subscribe(...)
的Action<Throwable>
部分。必須與toList()
有關。
訂閱時,你是否在onNext()中獲取物品? – Ritesh
你可以把doOnNext()放在toList()之前並嘗試。 – Ritesh
是的,我可以,我也很期待。問題是toList()調用。但是,我必須能夠創建一個列表。否則毫無意義。 –