Use of compose(RxTiPresenterUtils.deliverLatestCacheToView(this)) creates too many instances of OperatorSemaphore
When using your lib, I noticed weird side-effect, when using
compose(RxTiPresenterUtils.deliverLatestCacheToView(this))
it creates too many instances of OperatorSemaphore. After config changes and moving between screens with "Don't Keep Activities" flag. I tried to trigger GC, but it didn't help.

On the opposite side using
compose(RxTiPresenterUtils.deliverToView(this))
worked just fine. Firstly, it didn't create so many instances, secondly, after triggering GC, the existing instances of OperatorSemaphore was destroyed.
I did look into the internals of caching version it seemed to me that after presenter is destroyed lifecycle observers should be removed therefore triggering GC should clear OperatorSemaphore instances.
Can you better explain how it should work, and when GC should clear out those instances.
Couple of unrelated questions
- Should
deliverLatestCacheToViewpropagate cached Error? - Any actions with view in
doOnSubscribe/doOnTerminatewill crash the app when user will leave and go back to view during network request. I expect isViewReady(presenter) will emit items and deliver cache only when view fully attached.
Full code
@Override protected void onWakeUp() {
super.onWakeUp();
loadChats();
}
public void loadChats() {
rxSubscriptionHelper.manageSubscription(
chatOperations.getChats(chatType)
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(() -> {
if (getView() != null) {
getView().showRefreshing();
}
})
.doOnTerminate(() -> {
if (getView() != null) {
getView().stopRefresginAndHideMsgs();
}
})
.compose(RxTiPresenterUtils.deliverLatestCacheToView(this))
.subscribe(chats -> {
getView().setChats(chats);
}, e -> {
if (e instanceof RxNetworkException) {
getView().stopRefreshAndShowError(e.getMessage());
} else {
throw new RuntimeException(e);
}
})
);
}