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: Deanonymize operators #549

Merged
merged 3 commits into from
May 30, 2018

Conversation

akarnokd
Copy link
Collaborator

This PR factors out the use of AnonymousObservable in standard operators for two reasons:

  • avoid the stateful delegate allocation when chaining operators.
  • have a proper name for the operator in stacktraces.

@danielcweber
Copy link
Collaborator

LGTM overall, can you centralize that OnNext-ignoring observer, definitely avoid copy-and-paste, maybe make it an extension for observers?

@akarnokd
Copy link
Collaborator Author

Maybe as a separate PR?

@danielcweber
Copy link
Collaborator

Sure.

if (Kind == NotificationKind.OnNext)
protected override IDisposable SubscribeCore(IObserver<T> observer)
{
return scheduler.Schedule(new State { parent = parent, observer = observer }, (scheduler, state) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a ValueTuple e.g. (parent, observer)

@@ -57,22 +121,69 @@ public virtual IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Tas

public virtual IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task<IDisposable>> subscribeAsync)
{
return new AnonymousObservable<TResult>(observer =>
return new CreateWithTaskDisposable<TResult>(subscribeAsync);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code reuse or inheritance or something similar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? I've mentioned the benefits of these changes in the PR text.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean those IObserver-implementors that are duplicated. There is a good chance for code reuse I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other implementation are you refering to?

Copy link
Collaborator Author

@akarnokd akarnokd May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Func<IObserver<TResult>, CancellationToken, Task<Action>> subscribeAsync
Func<IObserver<TResult>, CancellationToken, Task<IDisposable>> subscribeAsync

Action != IDisposable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common base class might be possible, but nevermind, it's good as it is.

@danielcweber
Copy link
Collaborator

Just one more thing, have you considered using ContinueWith on the Tasks instead of converting them with ToObservable? You can pass it a state and possibly save some allocations. Might as well happen in a future PR.

@akarnokd
Copy link
Collaborator Author

Maybe in a later PR, the aim in this PR to avoid those anonymous instances and intermediate delegates.

@danielcweber danielcweber merged commit 088fc52 into dotnet:master May 30, 2018
@akarnokd akarnokd deleted the NoAnonymousObservable branch June 26, 2018 21:37
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