Browse Source

Merge branch 'main' into dev/bartde/split_disposable_public_internal

Bart J.F. De Smet 5 years ago
parent
commit
39b9971c68

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs

@@ -163,7 +163,7 @@ namespace System.Reactive.Concurrency
                 _state = state;
                 _action = action;
 
-                Disposable.SetSingle(ref _timer, new System.Threading.Timer(@this => Tick(@this!), this, dueTime, TimeSpan.FromMilliseconds(Timeout.Infinite)));
+                Disposable.SetSingle(ref _timer, new System.Threading.Timer(static @this => Tick(@this!), this, dueTime, TimeSpan.FromMilliseconds(Timeout.Infinite)));
             }
 
             private static void Tick(object state)
@@ -207,7 +207,7 @@ namespace System.Reactive.Concurrency
                 // Rooting of the timer happens through the timer's state
                 // which is the current instance and has a field to store the Timer instance.
                 //
-                _timer = new System.Threading.Timer(@this => Tick(@this!), this, period, period);
+                _timer = new System.Threading.Timer(static @this => Tick(@this!), this, period, period);
             }
 
             private static void Tick(object state)
@@ -239,7 +239,7 @@ namespace System.Reactive.Concurrency
             {
                 _action = action;
 
-                new Thread(@this => Loop(@this!))
+                new Thread(static @this => Loop(@this!))
                 {
                     Name = "Rx-FastPeriodicTimer",
                     IsBackground = true

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs

@@ -235,7 +235,7 @@ namespace System.Reactive.Concurrency
                 var sad = new SingleAssignmentDisposable();
 
                 Group.Add(sad);
-                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), time, nextState => {
+                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), time, static nextState => {
                     [email protected](nextState.sad);
                     [email protected](nextState.state);
                 });

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEvent.cs

@@ -292,7 +292,7 @@ namespace System.Reactive.Linq.ObservableImpl
                             {
                                 if (--@this._count == 0)
                                 {
-                                    closureParent._scheduler.ScheduleAction(@this._removeHandler, handler => handler.Dispose());
+                                    closureParent._scheduler.ScheduleAction(@this._removeHandler, static handler => handler.Dispose());
                                     closureParent._session = null;
                                 }
                             }

+ 8 - 10
Rx.NET/Source/src/System.Reactive/Linq/Observable/Generate.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
 
@@ -52,16 +50,16 @@ namespace System.Reactive.Linq.ObservableImpl
                 private TState _state;
                 private bool _first;
 
-                public void Run(IScheduler _scheduler)
+                public void Run(IScheduler scheduler)
                 {
-                    var longRunning = _scheduler.AsLongRunning();
+                    var longRunning = scheduler.AsLongRunning();
                     if (longRunning != null)
                     {
-                        SetUpstream(longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
+                        SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
                     }
                     else
                     {
-                        SetUpstream(_scheduler.Schedule(this, (@this, a) => @this.LoopRec(a)));
+                        SetUpstream(scheduler.Schedule(this, static (@this, a) => @this.LoopRec(a)));
                     }
                 }
 
@@ -205,7 +203,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     var timer = new SingleAssignmentDisposable();
                     Disposable.TrySetMultiple(ref _timerDisposable, timer);
-                    timer.Disposable = outerScheduler.Schedule((@this: this, initialState), (scheduler, tuple) => [email protected](scheduler, tuple.initialState));
+                    timer.Disposable = outerScheduler.Schedule((@this: this, initialState), static (scheduler, tuple) => [email protected](scheduler, tuple.initialState));
                 }
 
                 protected override void Dispose(bool disposing)
@@ -256,7 +254,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                     var timer = new SingleAssignmentDisposable();
                     Disposable.TrySetMultiple(ref _timerDisposable, timer);
-                    timer.Disposable = self.Schedule((@this: this, state), time, (scheduler, tuple) => [email protected](scheduler, tuple.state));
+                    timer.Disposable = self.Schedule((@this: this, state), time, static (scheduler, tuple) => [email protected](scheduler, tuple.state));
 
                     return Disposable.Empty;
                 }
@@ -314,7 +312,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     var timer = new SingleAssignmentDisposable();
                     Disposable.TrySetMultiple(ref _timerDisposable, timer);
-                    timer.Disposable = outerScheduler.Schedule((@this: this, initialState), (scheduler, tuple) => [email protected](scheduler, tuple.initialState));
+                    timer.Disposable = outerScheduler.Schedule((@this: this, initialState), static (scheduler, tuple) => [email protected](scheduler, tuple.initialState));
                 }
 
                 protected override void Dispose(bool disposing)
@@ -365,7 +363,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                     var timer = new SingleAssignmentDisposable();
                     Disposable.TrySetMultiple(ref _timerDisposable, timer);
-                    timer.Disposable = self.Schedule((@this: this, state), time, (scheduler, tuple) => [email protected](scheduler, tuple.state));
+                    timer.Disposable = self.Schedule((@this: this, state), time, static (scheduler, tuple) => [email protected](scheduler, tuple.state));
 
                     return Disposable.Empty;
                 }

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Linq/Observable/Range.cs

@@ -41,7 +41,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
             public void Run(IScheduler scheduler)
             {
-                var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                 Disposable.TrySetSingle(ref _task, first);
             }
 
@@ -61,7 +61,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     _index = idx + 1;
                     ForwardOnNext(idx);
-                    var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                    var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                     Disposable.TrySetMultiple(ref _task, next);
                 }
                 else
@@ -104,7 +104,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
             public void Run(ISchedulerLongRunning scheduler)
             {
-                SetUpstream(scheduler.ScheduleLongRunning(this, (@this, cancel) => @this.Loop(cancel)));
+                SetUpstream(scheduler.ScheduleLongRunning(this, static (@this, cancel) => @this.Loop(cancel)));
             }
 
             private void Loop(ICancelable cancel)

+ 6 - 6
Rx.NET/Source/src/System.Reactive/Linq/Observable/Repeat.cs

@@ -40,7 +40,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(IScheduler scheduler)
                 {
-                    var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
+                    var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
                     Disposable.TrySetSingle(ref _task, first);
                 }
 
@@ -57,7 +57,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     ForwardOnNext(_value);
 
-                    var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
+                    var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
                     Disposable.TrySetMultiple(ref _task, next);
 
                     return Disposable.Empty;
@@ -92,7 +92,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(ISchedulerLongRunning longRunning)
                 {
-                    SetUpstream(longRunning.ScheduleLongRunning(this, (@this, c) => @this.LoopInf(c)));
+                    SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, c) => @this.LoopInf(c)));
                 }
 
                 private void LoopInf(ICancelable cancel)
@@ -142,7 +142,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(IScheduler scheduler)
                 {
-                    var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                    var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                     Disposable.TrySetSingle(ref _task, first);
                 }
 
@@ -170,7 +170,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     else
                     {
-                        var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                        var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                         Disposable.TrySetMultiple(ref _task, next);
                     }
                     return Disposable.Empty;
@@ -209,7 +209,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(ISchedulerLongRunning longRunning)
                 {
-                    SetUpstream(longRunning.ScheduleLongRunning(this, (@this, cancel) => @this.Loop(cancel)));
+                    SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, cancel) => @this.Loop(cancel)));
                 }
 
                 private void Loop(ICancelable cancel)

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Return.cs

@@ -34,7 +34,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
             public void Run(IScheduler scheduler)
             {
-                SetUpstream(scheduler.ScheduleAction(this, @this => @this.Invoke()));
+                SetUpstream(scheduler.ScheduleAction(this, static @this => @this.Invoke()));
             }
 
             private void Invoke()

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs

@@ -592,7 +592,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     else
                     {
-                        task.ContinueWithState((t, tuple) => [email protected](tuple.value, t), (@this: this, value), _cancel.Token);
+                        task.ContinueWithState(static (t, tuple) => [email protected](tuple.value, t), (@this: this, value), _cancel.Token);
                     }
                 }
 
@@ -750,7 +750,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     else
                     {
-                        task.ContinueWithState((t, tuple) => [email protected](tuple.value, tuple.index, t), (@this: this, value, index), _cancel.Token);
+                        task.ContinueWithState(static (t, tuple) => [email protected](tuple.value, tuple.index, t), (@this: this, value, index), _cancel.Token);
                     }
                 }
 

+ 6 - 6
Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs

@@ -70,11 +70,11 @@ namespace System.Reactive.Linq.ObservableImpl
                     var longRunning = _loopScheduler.AsLongRunning();
                     if (longRunning != null)
                     {
-                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
+                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
                     }
                     else
                     {
-                        var first = _loopScheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                        var first = _loopScheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                         Disposable.TrySetSingle(ref _loopDisposable, first);
                     }
                 }
@@ -85,7 +85,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     {
                         ForwardOnNext(_queue.Dequeue());
 
-                        var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                        var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                         Disposable.TrySetMultiple(ref _loopDisposable, next);
                     }
                     else
@@ -186,11 +186,11 @@ namespace System.Reactive.Linq.ObservableImpl
                     var longRunning = _loopScheduler.AsLongRunning();
                     if (longRunning != null)
                     {
-                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
+                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
                     }
                     else
                     {
-                        var first = _loopScheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                        var first = _loopScheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                         Disposable.TrySetSingle(ref _loopDisposable, first);
                     }
                 }
@@ -201,7 +201,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     {
                         ForwardOnNext(_queue.Dequeue().Value);
 
-                        var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                        var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
                         Disposable.TrySetMultiple(ref _loopDisposable, next);
                     }
                     else

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Throttle.cs

@@ -67,7 +67,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 }
 
                 Disposable.TrySetSerial(ref _serialCancelable, null);
-                Disposable.TrySetSerial(ref _serialCancelable, _scheduler.ScheduleAction((@this: this, currentid), _dueTime, tuple => [email protected](tuple.currentid)));
+                Disposable.TrySetSerial(ref _serialCancelable, _scheduler.ScheduleAction((@this: this, currentid), _dueTime, static tuple => [email protected](tuple.currentid)));
             }
 
             private void Propagate(ulong currentid)

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Throw.cs

@@ -34,7 +34,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
             public void Run(IScheduler scheduler)
             {
-                SetUpstream(scheduler.ScheduleAction(this, @this => @this.ForwardOnError(@this._exception)));
+                SetUpstream(scheduler.ScheduleAction(this, static @this => @this.ForwardOnError(@this._exception)));
             }
         }
     }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Timeout.cs

@@ -161,7 +161,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(Absolute parent)
                 {
-                    SetUpstream(parent._scheduler.ScheduleAction(this, parent._dueTime, @this => @this.Timeout()));
+                    SetUpstream(parent._scheduler.ScheduleAction(this, parent._dueTime, static @this => @this.Timeout()));
 
                     Disposable.TrySetSingle(ref _serialDisposable, parent._source.SubscribeSafe(this));
                 }

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Linq/Observable/Timer.cs

@@ -130,7 +130,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                 public void Run(Periodic parent, DateTimeOffset dueTime)
                 {
-                    SetUpstream(parent._scheduler.Schedule(this, dueTime, (innerScheduler, @this) => @this.InvokeStart(innerScheduler)));
+                    SetUpstream(parent._scheduler.Schedule(this, dueTime, static (innerScheduler, @this) => @this.InvokeStart(innerScheduler)));
                 }
 
                 public void Run(Periodic parent, TimeSpan dueTime)
@@ -140,11 +140,11 @@ namespace System.Reactive.Linq.ObservableImpl
                     //
                     if (dueTime == _period)
                     {
-                        SetUpstream(parent._scheduler.SchedulePeriodic(this, _period, @this => @this.Tick()));
+                        SetUpstream(parent._scheduler.SchedulePeriodic(this, _period, static @this => @this.Tick()));
                     }
                     else
                     {
-                        SetUpstream(parent._scheduler.Schedule(this, dueTime, (innerScheduler, @this) => @this.InvokeStart(innerScheduler)));
+                        SetUpstream(parent._scheduler.Schedule(this, dueTime, static (innerScheduler, @this) => @this.InvokeStart(innerScheduler)));
                     }
                 }
 
@@ -227,7 +227,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     var d = new SingleAssignmentDisposable();
                     _periodic = d;
                     _index = 1;
-                    d.Disposable = self.SchedulePeriodic(this, _period, @this => @this.Tock());
+                    d.Disposable = self.SchedulePeriodic(this, _period, static @this => @this.Tock());
 
                     try
                     {
@@ -247,7 +247,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     //
                     if (Interlocked.Decrement(ref _pendingTickCount) > 0)
                     {
-                        var c = self.Schedule((@this: this, index: 1L), (tuple, action) => [email protected](tuple.index, action));
+                        var c = self.Schedule((@this: this, index: 1L), static (tuple, action) => [email protected](tuple.index, action));
 
                         return StableCompositeDisposable.Create(d, c);
                     }

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Linq/Observable/ToObservable.cs

@@ -52,7 +52,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 // is used to have LoopRec bail out and perform proper clean-up of the
                 // enumerator.
                 //
-                scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
             }
 
             protected override void Dispose(bool disposing)
@@ -119,7 +119,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 // is used to have LoopRec bail out and perform proper clean-up of the
                 // enumerator.
                 //
-                scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
+                scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
 
                 return Disposable.Empty;
             }
@@ -162,7 +162,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     return;
                 }
 
-                SetUpstream(scheduler.ScheduleLongRunning((@this: this, e), (tuple, cancelable) => [email protected](tuple.e, cancelable)));
+                SetUpstream(scheduler.ScheduleLongRunning((@this: this, e), static (tuple, cancelable) => [email protected](tuple.e, cancelable)));
             }
 
             private void Loop(IEnumerator<TSource> enumerator, ICancelable cancel)

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Linq/Observable/Window.cs

@@ -210,7 +210,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         _nextShift += _timeShift;
                     }
 
-                    m.Disposable = _scheduler.ScheduleAction((@this: this, isSpan, isShift), ts, tuple => [email protected](tuple.isSpan, tuple.isShift));
+                    m.Disposable = _scheduler.ScheduleAction((@this: this, isSpan, isShift), ts, static tuple => [email protected](tuple.isSpan, tuple.isShift));
                 }
 
                 private void Tick(bool isSpan, bool isShift)
@@ -313,7 +313,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                     CreateWindow();
 
-                    groupDisposable.Add(parent._scheduler.SchedulePeriodic(this, parent._timeSpan, @this => @this.Tick()));
+                    groupDisposable.Add(parent._scheduler.SchedulePeriodic(this, parent._timeSpan, static @this => @this.Tick()));
                     groupDisposable.Add(parent._source.SubscribeSafe(this));
 
                     SetUpstream(_refCountDisposable);
@@ -424,7 +424,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     var m = new SingleAssignmentDisposable();
                     _timerD.Disposable = m;
 
-                    m.Disposable = _scheduler.ScheduleAction((@this: this, window), _timeSpan, tuple => [email protected](tuple.window));
+                    m.Disposable = _scheduler.ScheduleAction((@this: this, window), _timeSpan, static tuple => [email protected](tuple.window));
                 }
 
                 private void Tick(Subject<TSource> window)
@@ -542,7 +542,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
                     groupDisposable.Add(source.SubscribeSafe(this));
 
-                    _windowGate.Wait(this, @this => @this.CreateWindowClose());
+                    _windowGate.Wait(this, static @this => @this.CreateWindowClose());
 
                     SetUpstream(_refCountDisposable);
                 }
@@ -581,7 +581,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         ForwardOnNext(window);
                     }
 
-                    _windowGate.Wait(this, @this => @this.CreateWindowClose());
+                    _windowGate.Wait(this, static @this => @this.CreateWindowClose());
                 }
 
                 private sealed class WindowClosingObserver : SafeObserver<TWindowClosing>