deliverLatestCacheToView delivers all previously emitted items
Opened this issue · 4 comments
RxTiPresenterUtils.deliverLatestCacheToView
caches and re-delivers all items emitted by the source.
Look at this log output. When the view is detached, several items are emitted by the source, but not delivered. This is correct so far.
After the view is reattached, all of the items are delivered again, including those which had already been delivered (c9915aa
) and those which should have been dropped (6b60904
).
11-02 12:45:45.392 D: Emitting c9915aa
11-02 12:45:45.421 I: Delivering c9915aa
11-02 12:46:02.199 D: Emitting 75d8118
11-02 12:46:02.210 I: Delivering 75d8118
11-02 12:46:02.211 D: Emitting a0e7956
11-02 12:46:02.255 I: Delivering a0e7956
VIEW DETACHED
11-02 12:46:44.932 D: Emitting 6b60904
11-02 12:46:45.052 D: Emitting 27a3122
11-02 12:46:45.668 D: Emitting 50cb170
11-02 12:46:45.682 D: Emitting 1ae3d6e
11-02 12:46:46.478 D: Emitting efbdc0f
11-02 12:46:46.493 D: Emitting b085ea5
VIEW REATTACHED
11-02 12:47:09.806 I: Delivering c9915aa
11-02 12:47:09.807 I: Delivering 75d8118
11-02 12:47:09.807 I: Delivering a0e7956
11-02 12:47:09.808 I: Delivering 6b60904
11-02 12:47:09.809 I: Delivering 27a3122
11-02 12:47:09.809 I: Delivering 50cb170
11-02 12:47:09.810 I: Delivering 1ae3d6e
11-02 12:47:09.811 I: Delivering efbdc0f
11-02 12:47:09.812 I: Delivering b085ea5
11-02 12:47:15.458 D: Emitting 4cdffd
11-02 12:47:15.459 I: Delivering 4cdffd
Here is the code:
val subscription =
Observable.just(/* some object */)
.doOnNext { c -> Timber.d("Emitting %x".format(c.hashCode())) }
.delaySubscription(5, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(RxTiPresenterUtils.deliverLatestCacheToView<Object>(this))
.subscribe { c ->
Timber.i("Delivering %x".format(c.hashCode()))
view.showData(c)
}
rxHelper.manageSubscription(subscription)
Is this the expected behaviour?
There is similar strange behaviour with deliverLatestToView
(the variant without the caching).
Again, this delivers all of the items which should have been dropped while the view was detached, but it delivers them in a different order. Is this a threading bug?
11-02 13:53:57.080 D: Emitting 21ea0e8
11-02 13:53:57.086 D: Emitting 207a5a6
11-02 13:53:57.956 D: Emitting 1b0e394
11-02 13:53:57.973 D: Emitting 9f87632
11-02 13:53:58.746 D: Emitting 182a500
11-02 13:53:58.759 D: Emitting 3b3c37e
11-02 13:54:06.459 I: Delivering 21ea0e8
11-02 13:54:06.460 I: Delivering 1b0e394
11-02 13:54:06.461 I: Delivering 182a500
11-02 13:54:06.462 I: Delivering 207a5a6
11-02 13:54:06.463 I: Delivering 3b3c37e
The deliverLatestCacheToView
behavior is correct. All items, including the already delivered ones will be emitted again. Sending all items since the view was detached could be another operator. I'm waiting for a PR from you 😉
Can you post the code for your deliverLatestToView
example? These must be multiple Observables because deliverLatestToView
emits only the latest item. Neither the Observables nor the operators know each other. The order between emissions of different Observables cannot be guaranteed.
If the cache behaviour is intentional, then I think it doesn't match the documentation:
If the transformer receives a next value while the previous value has not been delivered, the previous value will be dropped.
You are right about the deliverLatestToView
variant. There were multiple Observables involved - sorry for the noise. :)
- update documentation