Skip to content
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

4.x: Make Never<TResult> singleton. #513

Merged
merged 1 commit into from
May 26, 2018

Conversation

akarnokd
Copy link
Collaborator

This PR turns the operator of Never() into a singleton instance as, in theory, nothing should rely on the identity of it (i.e., something expecting Never() != Never()).

Unfortunately, there is something in Rx.NET itself that relies on object identity: the Join pattern's use of Dictionary where the key is the source observable:

Plan.cs#L96

which would crash And:

System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
System.Reactive.Joins.ActivePlan.AddJoinObserver(IJoinObserver joinObserver)
System.Reactive.Joins.ActivePlan`2..ctor(JoinObserver`1 first, JoinObserver`1 second, Action`2 onNext, Action onCompleted)
System.Reactive.Joins.Plan`3.Activate(Dictionary`2 externalSubscriptions, IObserver`1 observer, Action`1 deactivate)
System.Reactive.Linq.QueryLanguage.<>c__DisplayClass421_0`1.<When>b__0(IObserver`1 observer)

in ObservableJoinsTest.cs#L1596

The larger question is, should the following be possible with And in the first place?

var source = Observable.Range(1, 5);

When(
    source.And(source).Then((a, b) => a + b)
);

@akarnokd
Copy link
Collaborator Author

The RxJava version of the join patterns, which was directly ported some time ago, does not have this problem (due to this) and the example above correctly generates 2, 4, 6, 8, 10.

@clairernovotny clairernovotny merged commit a4cc80f into dotnet:master May 26, 2018
@akarnokd akarnokd deleted the NeverSingleton branch May 30, 2018 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants