JakeWharton / RxReplayingShare

An RxJava transformer which combines replay(1), publish(), and refCount() operators.
Apache License 2.0
626 stars 28 forks source link

Clear lastSeen on disposal of upstream #27

Closed realdadfish closed 6 years ago

realdadfish commented 6 years ago

I figured that if I use RxReplayingShare to re-connect to a previously disposed upstream (i.e. after all original subscriptions where disposed), it would return me the previously cached / invalid value of the now dead upstream before querying the new upstream for data.

IMHO

val lastSeen = LastSeen<T>()
LastSeenObservable<T>(
  upstream
    .doOnNext(lastSeen)
    .share(),
  lastSeen
)

should become

val lastSeen = LastSeen<T>()
LastSeenObservable<T>(
  upstream
    .doOnNext(lastSeen)
    .doOnDispose { lastSeen.value = null }
    .share(),
  lastSeen
)

This fixed the issue for me. What do you think?

realdadfish commented 6 years ago

Hrm - ok, I think this might be a duplicate of #25. Also I guess doOnFinally {} seems to be the proper callback. Sorry for the noise.

JakeWharton commented 6 years ago

25 is about error/completion from upstream. Your issue is about disposal from downstream. I'm pretty sure you should just be using replay(1).refCount() and not this library.

realdadfish commented 6 years ago

The solution with doFinally proposed in #25 will also fix my problem, so I'm fine with that :)