-
Notifications
You must be signed in to change notification settings - Fork 754
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: Inline Disposable.Create #580
Conversation
SetUpstream(StableCompositeDisposable.Create(fstSubscription, sndSubscription, fstO, sndO)); | ||
// clearing the queue should happen under the lock | ||
// as they are plain Queue<T>s, not concurrent queues. | ||
lock (_gate) |
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.
This has now become dangerous, _gate might not be assigned.
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.
Can Dispose
happen before Run
executes?
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.
Hopefully not in our code, but it's good to assume everything might be disposed right away. By the same reasoning, Run will definitely happen when the Sink was created, so the gate might be created while constructing.
{ | ||
Disposable.TryDispose(ref _subscriptions[i]); | ||
} | ||
lock (_gate) |
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.
This has now become dangerous, _gate might not be assigned.
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.
I'll move the creation into the constructor so it will be guaranteed to exist.
{ | ||
var o = new SourceObserver(this, i); | ||
Disposable.SetSingle(ref _subscriptions[i], srcs[i].SubscribeSafe(o)); | ||
_gate = new object(); |
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.
I know it's safe now but please just make it a readonly field and assign it in the declaration.
This PR inlines the
Disposable.Create(Action)
invocations, saving on an allocation and some indirection.