Skip to content

Commit f99de54

Browse files
authored
Merge pull request #1360 from dotnet/dev/bartde/more_static_lambdas
More static lambdas in Rx.
2 parents 15f1cc6 + 6298cb5 commit f99de54

File tree

15 files changed

+47
-49
lines changed

15 files changed

+47
-49
lines changed

Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Timer(Action<object?> action, object? state, TimeSpan dueTime)
163163
_state = state;
164164
_action = action;
165165

166-
Disposable.SetSingle(ref _timer, new System.Threading.Timer(@this => Tick(@this!), this, dueTime, TimeSpan.FromMilliseconds(Timeout.Infinite)));
166+
Disposable.SetSingle(ref _timer, new System.Threading.Timer(static @this => Tick(@this!), this, dueTime, TimeSpan.FromMilliseconds(Timeout.Infinite)));
167167
}
168168

169169
private static void Tick(object state)
@@ -207,7 +207,7 @@ public PeriodicTimer(Action action, TimeSpan period)
207207
// Rooting of the timer happens through the timer's state
208208
// which is the current instance and has a field to store the Timer instance.
209209
//
210-
_timer = new System.Threading.Timer(@this => Tick(@this!), this, period, period);
210+
_timer = new System.Threading.Timer(static @this => Tick(@this!), this, period, period);
211211
}
212212

213213
private static void Tick(object state)
@@ -239,7 +239,7 @@ public FastPeriodicTimer(Action action)
239239
{
240240
_action = action;
241241

242-
new Thread(@this => Loop(@this!))
242+
new Thread(static @this => Loop(@this!))
243243
{
244244
Name = "Rx-FastPeriodicTimer",
245245
IsBackground = true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private void InvokeNext(TState state, TimeSpan time)
235235
var sad = new SingleAssignmentDisposable();
236236

237237
Group.Add(sad);
238-
sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), time, nextState => {
238+
sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), time, static nextState => {
239239
nextState.@this.Group.Remove(nextState.sad);
240240
nextState.@this.InvokeFirst(nextState.state);
241241
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public IDisposable Connect(IObserver<TArgs> observer)
292292
{
293293
if (--@this._count == 0)
294294
{
295-
closureParent._scheduler.ScheduleAction(@this._removeHandler, handler => handler.Dispose());
295+
closureParent._scheduler.ScheduleAction(@this._removeHandler, static handler => handler.Dispose());
296296
closureParent._session = null;
297297
}
298298
}

Rx.NET/Source/src/System.Reactive/Linq/Observable/Generate.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT License.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System.Reactive.Concurrency;
86
using System.Reactive.Disposables;
97

@@ -52,16 +50,16 @@ public _(NoTime parent, IObserver<TResult> observer)
5250
private TState _state;
5351
private bool _first;
5452

55-
public void Run(IScheduler _scheduler)
53+
public void Run(IScheduler scheduler)
5654
{
57-
var longRunning = _scheduler.AsLongRunning();
55+
var longRunning = scheduler.AsLongRunning();
5856
if (longRunning != null)
5957
{
60-
SetUpstream(longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
58+
SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
6159
}
6260
else
6361
{
64-
SetUpstream(_scheduler.Schedule(this, (@this, a) => @this.LoopRec(a)));
62+
SetUpstream(scheduler.Schedule(this, static (@this, a) => @this.LoopRec(a)));
6563
}
6664
}
6765

@@ -205,7 +203,7 @@ public void Run(IScheduler outerScheduler, TState initialState)
205203
{
206204
var timer = new SingleAssignmentDisposable();
207205
Disposable.TrySetMultiple(ref _timerDisposable, timer);
208-
timer.Disposable = outerScheduler.Schedule((@this: this, initialState), (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.initialState));
206+
timer.Disposable = outerScheduler.Schedule((@this: this, initialState), static (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.initialState));
209207
}
210208

211209
protected override void Dispose(bool disposing)
@@ -256,7 +254,7 @@ private IDisposable InvokeRec(IScheduler self, TState state)
256254

257255
var timer = new SingleAssignmentDisposable();
258256
Disposable.TrySetMultiple(ref _timerDisposable, timer);
259-
timer.Disposable = self.Schedule((@this: this, state), time, (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.state));
257+
timer.Disposable = self.Schedule((@this: this, state), time, static (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.state));
260258

261259
return Disposable.Empty;
262260
}
@@ -314,7 +312,7 @@ public void Run(IScheduler outerScheduler, TState initialState)
314312
{
315313
var timer = new SingleAssignmentDisposable();
316314
Disposable.TrySetMultiple(ref _timerDisposable, timer);
317-
timer.Disposable = outerScheduler.Schedule((@this: this, initialState), (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.initialState));
315+
timer.Disposable = outerScheduler.Schedule((@this: this, initialState), static (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.initialState));
318316
}
319317

320318
protected override void Dispose(bool disposing)
@@ -365,7 +363,7 @@ private IDisposable InvokeRec(IScheduler self, TState state)
365363

366364
var timer = new SingleAssignmentDisposable();
367365
Disposable.TrySetMultiple(ref _timerDisposable, timer);
368-
timer.Disposable = self.Schedule((@this: this, state), time, (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.state));
366+
timer.Disposable = self.Schedule((@this: this, state), time, static (scheduler, tuple) => tuple.@this.InvokeRec(scheduler, tuple.state));
369367

370368
return Disposable.Empty;
371369
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public RangeSink(int start, int count, IObserver<int> observer)
4141

4242
public void Run(IScheduler scheduler)
4343
{
44-
var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
44+
var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
4545
Disposable.TrySetSingle(ref _task, first);
4646
}
4747

@@ -61,7 +61,7 @@ private IDisposable LoopRec(IScheduler scheduler)
6161
{
6262
_index = idx + 1;
6363
ForwardOnNext(idx);
64-
var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
64+
var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
6565
Disposable.TrySetMultiple(ref _task, next);
6666
}
6767
else
@@ -104,7 +104,7 @@ public RangeSink(int start, int count, IObserver<int> observer)
104104

105105
public void Run(ISchedulerLongRunning scheduler)
106106
{
107-
SetUpstream(scheduler.ScheduleLongRunning(this, (@this, cancel) => @this.Loop(cancel)));
107+
SetUpstream(scheduler.ScheduleLongRunning(this, static (@this, cancel) => @this.Loop(cancel)));
108108
}
109109

110110
private void Loop(ICancelable cancel)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public _(TResult value, IObserver<TResult> observer)
4040

4141
public void Run(IScheduler scheduler)
4242
{
43-
var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
43+
var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
4444
Disposable.TrySetSingle(ref _task, first);
4545
}
4646

@@ -57,7 +57,7 @@ private IDisposable LoopRecInf(IScheduler scheduler)
5757
{
5858
ForwardOnNext(_value);
5959

60-
var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
60+
var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRecInf(innerScheduler));
6161
Disposable.TrySetMultiple(ref _task, next);
6262

6363
return Disposable.Empty;
@@ -92,7 +92,7 @@ public _(TResult value, IObserver<TResult> observer)
9292

9393
public void Run(ISchedulerLongRunning longRunning)
9494
{
95-
SetUpstream(longRunning.ScheduleLongRunning(this, (@this, c) => @this.LoopInf(c)));
95+
SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, c) => @this.LoopInf(c)));
9696
}
9797

9898
private void LoopInf(ICancelable cancel)
@@ -142,7 +142,7 @@ public _(TResult value, int repeatCount, IObserver<TResult> observer)
142142

143143
public void Run(IScheduler scheduler)
144144
{
145-
var first = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
145+
var first = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
146146
Disposable.TrySetSingle(ref _task, first);
147147
}
148148

@@ -170,7 +170,7 @@ private IDisposable LoopRec(IScheduler scheduler)
170170
}
171171
else
172172
{
173-
var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
173+
var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
174174
Disposable.TrySetMultiple(ref _task, next);
175175
}
176176
return Disposable.Empty;
@@ -209,7 +209,7 @@ public _(TResult value, int remaining, IObserver<TResult> observer)
209209

210210
public void Run(ISchedulerLongRunning longRunning)
211211
{
212-
SetUpstream(longRunning.ScheduleLongRunning(this, (@this, cancel) => @this.Loop(cancel)));
212+
SetUpstream(longRunning.ScheduleLongRunning(this, static (@this, cancel) => @this.Loop(cancel)));
213213
}
214214

215215
private void Loop(ICancelable cancel)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public _(TResult value, IObserver<TResult> observer)
3434

3535
public void Run(IScheduler scheduler)
3636
{
37-
SetUpstream(scheduler.ScheduleAction(this, @this => @this.Invoke()));
37+
SetUpstream(scheduler.ScheduleAction(this, static @this => @this.Invoke()));
3838
}
3939

4040
private void Invoke()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ public override void OnNext(TSource value)
592592
}
593593
else
594594
{
595-
task.ContinueWithState((t, tuple) => tuple.@this.OnCompletedTask(tuple.value, t), (@this: this, value), _cancel.Token);
595+
task.ContinueWithState(static (t, tuple) => tuple.@this.OnCompletedTask(tuple.value, t), (@this: this, value), _cancel.Token);
596596
}
597597
}
598598

@@ -750,7 +750,7 @@ public override void OnNext(TSource value)
750750
}
751751
else
752752
{
753-
task.ContinueWithState((t, tuple) => tuple.@this.OnCompletedTask(tuple.value, tuple.index, t), (@this: this, value, index), _cancel.Token);
753+
task.ContinueWithState(static (t, tuple) => tuple.@this.OnCompletedTask(tuple.value, tuple.index, t), (@this: this, value, index), _cancel.Token);
754754
}
755755
}
756756

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public override void OnCompleted()
7070
var longRunning = _loopScheduler.AsLongRunning();
7171
if (longRunning != null)
7272
{
73-
Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
73+
Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
7474
}
7575
else
7676
{
77-
var first = _loopScheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
77+
var first = _loopScheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
7878
Disposable.TrySetSingle(ref _loopDisposable, first);
7979
}
8080
}
@@ -85,7 +85,7 @@ private IDisposable LoopRec(IScheduler scheduler)
8585
{
8686
ForwardOnNext(_queue.Dequeue());
8787

88-
var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
88+
var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
8989
Disposable.TrySetMultiple(ref _loopDisposable, next);
9090
}
9191
else
@@ -186,11 +186,11 @@ public override void OnCompleted()
186186
var longRunning = _loopScheduler.AsLongRunning();
187187
if (longRunning != null)
188188
{
189-
Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, (@this, c) => @this.Loop(c)));
189+
Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
190190
}
191191
else
192192
{
193-
var first = _loopScheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
193+
var first = _loopScheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
194194
Disposable.TrySetSingle(ref _loopDisposable, first);
195195
}
196196
}
@@ -201,7 +201,7 @@ private IDisposable LoopRec(IScheduler scheduler)
201201
{
202202
ForwardOnNext(_queue.Dequeue().Value);
203203

204-
var next = scheduler.Schedule(this, (innerScheduler, @this) => @this.LoopRec(innerScheduler));
204+
var next = scheduler.Schedule(this, static (innerScheduler, @this) => @this.LoopRec(innerScheduler));
205205
Disposable.TrySetMultiple(ref _loopDisposable, next);
206206
}
207207
else

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override void OnNext(TSource value)
6767
}
6868

6969
Disposable.TrySetSerial(ref _serialCancelable, null);
70-
Disposable.TrySetSerial(ref _serialCancelable, _scheduler.ScheduleAction((@this: this, currentid), _dueTime, tuple => tuple.@this.Propagate(tuple.currentid)));
70+
Disposable.TrySetSerial(ref _serialCancelable, _scheduler.ScheduleAction((@this: this, currentid), _dueTime, static tuple => tuple.@this.Propagate(tuple.currentid)));
7171
}
7272

7373
private void Propagate(ulong currentid)

0 commit comments

Comments
 (0)