-
Notifications
You must be signed in to change notification settings - Fork 762
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
BUG: RefCount with MinObservers > 1 Behaves Unexpectedly #2173
Comments
The documentation on RefCount(IConnectableObservable source, int minObservers) (as well as all RefCount overloads) states that the observable stays connected as long as there is one subscription to the source. This may be an error, but the functionality is consistent with documentation. Given that fact, the expected value would be as follows:
The exception looks like it's due to a bug here:
The error happens as follows: Subject<int> subj = new();
var refCount = subj.Publish().RefCount(minObservers: 2);
var sub1 = refCount.Subscribe(c => Console.WriteLine($"sub1: {c}")); // count == 1, doConnect = false
var sub2 = refCount.Subscribe(c => Console.WriteLine($"sub2: {c}")); // count == 2, doConnect = true, sets SingleAssignmentDisposableValue
sub1.Dispose(); // count == 1, no check to disconnect
var sub3 = refCount.Subscribe(c => Console.WriteLine($"sub3: {c}")); // count == 2, doConnect = true, sets already assigned SingleAssignmentDisposableValue, throwing an error The reason this doesn't happen when reactive/Rx.NET/Source/src/System.Reactive/Linq/Observable/RefCount.cs Lines 108 to 115 in fefe759
|
Code
Expected Output
I would expect not to receive values until
sub2
has subscribed. Then I would expect not to receive values aftersub1
is disposed. Then I would expect to receive values again aftersub3
has subscribed.Actual Output
sub2
should not have received value 4 since we were belowminObservers
at that point.sub3
subscribing.If this IS expected and not a bug, would love an explanation of what I'm misunderstanding. Thank you!
The text was updated successfully, but these errors were encountered: