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: Use Schedule calls with state #558

Merged
merged 5 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ protected override IDisposable SubscribeCore(IObserver<TSource> observer)
var d = new SerialDisposable();
d.Disposable = m;

m.Disposable = scheduler.Schedule(() =>
m.Disposable = scheduler.Schedule((source, observer, d),
(scheduler, state) =>
{
d.Disposable = new ScheduledDisposable(scheduler, source.SubscribeSafe(observer));
state.d.Disposable = new ScheduledDisposable(scheduler, state.source.SubscribeSafe(state.observer));
return Disposable.Empty;
});

return d;
Expand Down
2 changes: 1 addition & 1 deletion Rx.NET/Source/src/System.Reactive/Linq/Observable/Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private void DrainQueue(ICancelable cancel)
if (shouldWait)
{
var timer = new ManualResetEventSlim();
_scheduler.Schedule(waitTime, () => { timer.Set(); });
_scheduler.Schedule(timer, waitTime, (_, slimTimer) => { slimTimer.Set(); return Disposable.Empty; });

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,13 @@ public IDisposable Connect(IObserver<TArgs> observer)
{
if (--_count == 0)
{
_parent._scheduler.Schedule(_removeHandler.Dispose);
_parent._scheduler.ScheduleAction(_removeHandler, handler => handler.Dispose());
_parent._session = null;
}
}
});
}

}

private void Initialize()
Expand Down
3 changes: 2 additions & 1 deletion Rx.NET/Source/src/System.Reactive/Linq/Observable/Return.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -33,7 +34,7 @@ public _(TResult value, IObserver<TResult> observer, IDisposable cancel)

public IDisposable Run(IScheduler scheduler)
{
return scheduler.Schedule(Invoke);
return scheduler.ScheduleAction(this, @this => @this.Invoke());
}

private void Invoke()
Expand Down
5 changes: 3 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Skip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ public _(IObserver<TSource> observer, IDisposable cancel)

public IDisposable Run(Time parent)
{
var t = parent._scheduler.Schedule(parent._duration, Tick);
var t = parent._scheduler.Schedule(this, parent._duration, (_, state) => state.Tick());
var d = parent._source.SubscribeSafe(this);
return StableCompositeDisposable.Create(t, d);
}

private void Tick()
private IDisposable Tick()
{
_open = true;
return Disposable.Empty;
}

public override void OnNext(TSource value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ public _(IObserver<TSource> observer, IDisposable cancel)

public IDisposable Run(SkipUntil<TSource> parent)
{
var t = parent._scheduler.Schedule(parent._startTime, Tick);
var t = parent._scheduler.Schedule(this, parent._startTime, (_, state) => state.Tick());
var d = parent._source.SubscribeSafe(this);
return StableCompositeDisposable.Create(t, d);
}

private void Tick()
private IDisposable Tick()
{
_open = true;
return Disposable.Empty;
}

public override void OnNext(TSource value)
Expand Down
5 changes: 3 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Take.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,18 @@ public IDisposable Run(Time parent)
{
_gate = new object();

var t = parent._scheduler.Schedule(parent._duration, Tick);
var t = parent._scheduler.Schedule(this, parent._duration, (_, state) => state.Tick());
var d = parent._source.SubscribeSafe(this);
return StableCompositeDisposable.Create(t, d);
}

private void Tick()
private IDisposable Tick()
{
lock (_gate)
{
ForwardOnCompleted();
}
return Disposable.Empty;
}

public override void OnNext(TSource value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,18 @@ public _(IObserver<TSource> observer, IDisposable cancel)

public IDisposable Run(TakeUntil<TSource> parent)
{
var t = parent._scheduler.Schedule(parent._endTime, Tick);
var t = parent._scheduler.Schedule(this, parent._endTime, (_, state) => state.Tick());
var d = parent._source.SubscribeSafe(this);
return StableCompositeDisposable.Create(t, d);
}

private void Tick()
private IDisposable Tick()
{
lock (_gate)
{
ForwardOnCompleted();
}
return Disposable.Empty;
}

public override void OnNext(TSource value)
Expand Down
7 changes: 2 additions & 5 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Throw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -33,13 +34,9 @@ public _(Exception exception, IObserver<TResult> observer, IDisposable cancel)

public IDisposable Run(IScheduler scheduler)
{
return scheduler.Schedule(Invoke);
return scheduler.ScheduleAction(this, @this => @this.ForwardOnError(@this._exception));
}

private void Invoke()
{
ForwardOnError(_exception);
}
}
}
}
6 changes: 4 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public IDisposable Run(Absolute parent)

_switched = false;

var timer = parent._scheduler.Schedule(parent._dueTime, Timeout);
var timer = parent._scheduler.Schedule(this, parent._dueTime, (_, state) => state.Timeout());

original.Disposable = parent._source.SubscribeSafe(this);

return StableCompositeDisposable.Create(_subscription, timer);
}

private void Timeout()
private IDisposable Timeout()
{
var timerWins = false;

Expand All @@ -192,6 +192,8 @@ private void Timeout()

if (timerWins)
_subscription.Disposable = _other.SubscribeSafe(GetForwarder());

return Disposable.Empty;
}

public override void OnNext(TSource value)
Expand Down
7 changes: 4 additions & 3 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ public _(IObserver<long> observer, IDisposable cancel)

public IDisposable Run(Single parent, DateTimeOffset dueTime)
{
return parent._scheduler.Schedule(dueTime, Invoke);
return parent._scheduler.Schedule(this, dueTime, (_, state) => state.Invoke());
}

public IDisposable Run(Single parent, TimeSpan dueTime)
{
return parent._scheduler.Schedule(dueTime, Invoke);
return parent._scheduler.Schedule(this, dueTime, (_, state) => state.Invoke());
}

private void Invoke()
private IDisposable Invoke()
{
ForwardOnNext(0);
ForwardOnCompleted();
return Disposable.Empty;
}
}
}
Expand Down
Loading