-
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: Use Schedule calls with state #558
Changes from 1 commit
f65870f
037c341
c66e1fb
c17ec89
550a71d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,7 +414,7 @@ private void DrainQueue(ICancelable cancel) | |
if (shouldWait) | ||
{ | ||
var timer = new ManualResetEventSlim(); | ||
_scheduler.Schedule(waitTime, () => { timer.Set(); }); | ||
_scheduler.Schedule(timer, waitTime, (_, state) => { state.Set(); return Disposable.Empty; }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the extension I recently added. You may omit the scheduler parameter (_), won't have to return Disposable.Empty everywhere. Also, please give the inner variable a revealing name. I used to go for 'closureXYZ', e.g. closureTimer in this case. Just 'state' is not revealing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with that overload is that the parameters are after the lambda, which I find harder to read. Naming it like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the signature creates ambiguities unfortunately. If not 'closureTimer', at least something more revealing than 'state'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll rename these. You could introduce an internal extension under a different name but with the same ordering of arguments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can rename it in a subsequent PR and let ReSharper do the reordering. Would you then use the Action-extension for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the ordering of the parameters distracting with those Action overloads. I'd prefer this ordering and a renamed internal schedule method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I will file a PR with a renamed method and then we can get the Disposable.Empty out of that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
|
||
try | ||
{ | ||
|
@@ -473,7 +473,7 @@ protected override void RunCore(Absolute parent) | |
{ | ||
_ready = false; | ||
|
||
_cancelable.Disposable = parent._scheduler.Schedule(parent._dueTime, Start); | ||
_cancelable.Disposable = parent._scheduler.Schedule(this, parent._dueTime, (_, state) => { state.Start(); return Disposable.Empty; }); | ||
} | ||
|
||
private void Start() | ||
|
@@ -521,7 +521,7 @@ public L(Absolute parent, IObserver<TSource> observer, IDisposable cancel) | |
|
||
protected override void RunCore(Absolute parent) | ||
{ | ||
_cancelable.Disposable = parent._scheduler.Schedule(parent._dueTime, Start); | ||
_cancelable.Disposable = parent._scheduler.Schedule(this, parent._dueTime, (_, state) => { state.Start(); return Disposable.Empty; }); | ||
} | ||
|
||
private void Start() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,12 +284,19 @@ public IDisposable Connect(IObserver<TArgs> observer) | |
{ | ||
if (--_count == 0) | ||
{ | ||
_parent._scheduler.Schedule(_removeHandler.Dispose); | ||
_parent._scheduler.Schedule(_removeHandler, (_, self) => RemoveHandlerDispose(self)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'self', throughout calls to Schedule, has bee 'traditionally' used to denote the executing scheduler. If 'this' is passed as state, I like using @this as a name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll inline the method call back here. |
||
_parent._session = null; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
static IDisposable RemoveHandlerDispose(SingleAssignmentDisposable d) | ||
{ | ||
d.Dispose(); | ||
return Disposable.Empty; | ||
} | ||
|
||
private void Initialize() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Reactive.Concurrency; | ||
using System.Reactive.Disposables; | ||
|
||
namespace System.Reactive.Linq.ObservableImpl | ||
{ | ||
|
@@ -33,13 +34,14 @@ public _(TResult value, IObserver<TResult> observer, IDisposable cancel) | |
|
||
public IDisposable Run(IScheduler scheduler) | ||
{ | ||
return scheduler.Schedule(Invoke); | ||
return scheduler.Schedule(this, (_, self) => self.Invoke()); | ||
} | ||
|
||
private void Invoke() | ||
private IDisposable Invoke() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, consider the new extension and don't repeat returning Disposable.Empty. |
||
{ | ||
ForwardOnNext(_value); | ||
ForwardOnCompleted(); | ||
return Disposable.Empty; | ||
} | ||
} | ||
} | ||
|
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.
If you are using this overload, the scheduler will be passed. Convention throughout the rest of the code is to name it 'self' (now '_'). You can then omit it from the state-tuple.
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 was an odd case, wrapping the outer
scheduler
. I'm not sure if the inner scheduler would be the correct one in this situation.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.
It is generally just the executing one.