-
Notifications
You must be signed in to change notification settings - Fork 3k
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
cache behaving unexpected #1718
Comments
Also, an even worse example is o1.take(2).subscribe(ob("a1 "));
setTimeout(() => {
o1.take(2).subscribe(ob("b1 "));
}, 500);
setTimeout(() => {
o1.take(2).subscribe(ob("c1 "));
}, 1000);
setTimeout(() => {
o1.take(2).subscribe(ob("d1 "));
}, 1500); where |
This is working as designed. Your first source Observable (that logs When you create the first refCount subscriber to source1, you take three values, which unsubscribes from the source at the This is in contrast to source2, which emits a single value (52) and then completes, which puts the |
Hi, console.clear();
const {Observable} = Rx;
const observable = Observable.create(observer => {
console.log('effect');
observer.next('1');
return () => {
console.log('disposed');
}
}).cache(1);
let subscription1 = observable.subscribe(val => console.log(`subscription1: ${val}`));
setTimeout(() => {
subscription1.unsubscribe();
subscription2 = observable.subscribe(val => console.log(`subscription2: ${val}`));
}, 500) the output is this:
My issue is that I expect that if an observable was disposed the next subscription will act like the first one (= the cache would be cleared). Maybe this is not the design but is there a way to achieve this effect? |
Also I have places where I need to get the latest value in a one-time matter (.take(1)) and I don't care if there are other subscribers or not. In that scenario I will always get the cached value even when there are no active subscription, thus I'd get an old value, and if I use .take(2) on the scenario where there are other subscribers I might not unsubscribe for a very long while unnecessarily. |
3rd scenario where the current To sum up: |
What you say is false, i can add But beside that, my complain is not about the behavior of cache (whatever it might be), but about the unreliable behavior it shows. In my second example, you see i subscribe exactly the same 4x in a row, but it does different things from time to time. (Namely not printing the effect for If you are unable to reproduce this from my code sample, i can share the JsBin i used to test this in. |
The behavior you're describing is what happens when you refCount a
@Dorus I have submitted PR #1727 to address this issue, thanks for pointing it out. |
@trxcllnt Thanks! sorry for the issue hijack :) |
This should be resolved with #1727 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
result in:
What causes
effect B
to only play once, buteffect A
to play twice? Playing around with the code randomly seems to cause side-effects to appear and disappear on the source.Because
cache
works likepublishReplay().refCount()
, i would expecteffect B
to also play again aftera2 c
(a2 complete), but b2 does not seem to query the source again.On a possibly unrelated note,
cache
combines poorly with cold observables (or startWith) because it replays later values and then subscribes again. But this behavior is rather random because of the bug above.The text was updated successfully, but these errors were encountered: