-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish, Replay and Cache Operators #263
Publish, Replay and Cache Operators #263
Conversation
Cache operator as discussed in ReactiveX#209 Similar to `replay()` except that this auto-subscribes to the source sequence. This comes with the same cautions as `toList` when dealing with infinite or very large sequences.
Publish, Replay and Cache Operators
@Override | ||
public void run() { | ||
counter.incrementAndGet(); | ||
System.out.println("published observable being executed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still here (and twice below). :)
RxJava-pull-requests #134 FAILURE |
Hi, I noticed that calling Observable.replay() doesn't merely wrap the given observable into a ReplaySubject, but also combines this with OperationMulticast. I have several questions around this.
ConnectableObservable obs = sourceObservable.replay() s1 and s2 are entirely different subscriptions. Looking at the sources, s1 is a RepeatSubjectSubscription, which is put in an internal map and removed upon unsubscription. s1 however is an anonymous inner class instance in OperationMulticast which delegates to the subscription the sourceObservable would return normally. Now, to which one do I hold on and unsubscribe from when I want to go through a disconnect/reconnect cycle? I actually tried a few combinations and none worked for me. I either ended up triggering the sourceObservable twice upon reconnection (which I don't want) or I end up not getting previous emissions replayed on my observer. Any insight around this would be great. |
Have you read this? => http://northhorizon.net/2011/sharing-in-rx/ It helped me understand it quite a bit. Here is a snippet from it:
The reason Anything with If you just want simple caching behavior then the The Hope this helps. |
Thanks @benjchristensen, as always this was very helpful. I think what got me confused was the terminology. The fact that both replay() and cache() are implemented in terms of (Re)reading the article you posted (I did read it before, but that was before ReplaySubject had been released so it had slipped off my mind) and looking at the implementation, would you say this summary is correct:
|
Sorry I lost this question in my backlog ... Yes those summaries make sense to me. The
|
👍 |
…cache Publish, Replay and Cache Operators
(Redo of #260 after merging)
Added basic Publish (#15) and Replay (#71) operators to Observable. I have not done any of the overloads (particularly
Replay
which has 10+ in .Net.I also added a new
Cache
operator as discussed by @johngmyers and I at #209.Playing with
Replay
andConnectableObservable
it does not cater well to the typical use case of needing to just de-dupe calls (cache the responses) so thisCache
operator can be thought of as an automatic version ofReplay
. It comes with the same risk astoList
if used with infinite or very large sequences as you can not unsubscribe from it.