Skip to content

Commit f82265d

Browse files
committed
fix: mark more parts of code .net 6 only
1 parent c408f04 commit f82265d

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

src/TimeScheduler/PeriodicTimer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if NET6_0_OR_GREATER
12
namespace TimeScheduler;
23

34
/// <summary>Provides a periodic timer that enables waiting asynchronously for timer ticks.</summary>
@@ -44,3 +45,4 @@ protected virtual void Dispose(bool disposing)
4445
{
4546
}
4647
}
48+
#endif

src/TimeScheduler/System/Threading/Tasks/TimeProviderTaskExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public DelayState() : base() { }
2525
public CancellationTokenRegistration Registration { get; set; }
2626
}
2727

28+
#if NET6_0_OR_GREATER
2829
private sealed class WaitAsyncState : TaskCompletionSource<bool>
2930
{
3031
// The original code passed TaskCreationOptions.RunContinuationsAsynchronously to the base constructor,
@@ -36,6 +37,7 @@ public WaitAsyncState() : base() { }
3637
public CancellationTokenRegistration Registration;
3738
public ITimer? Timer;
3839
}
40+
#endif
3941

4042
/// <summary>Creates a task that completes after a specified time interval.</summary>
4143
/// <param name="timeProvider">The <see cref="TimeProvider"/> with which to interpret <paramref name="delay"/>.</param>
@@ -106,6 +108,8 @@ public static Task Delay(this TimeProvider timeProvider, TimeSpan delay, Cancell
106108
return state.Task;
107109
}
108110

111+
#if NET6_0_OR_GREATER
112+
109113
/// <summary>
110114
/// Gets a <see cref="Task"/> that will complete when this <see cref="Task"/> completes, when the specified timeout expires, or when the specified <see cref="CancellationToken"/> has cancellation requested.
111115
/// </summary>
@@ -223,6 +227,8 @@ public static async Task<TResult> WaitAsync<TResult>(this Task<TResult> task, Ti
223227
return task.Result;
224228
#pragma warning restore CA1849 // Call async methods when in an async method
225229
}
230+
231+
#endif
226232
}
227233
#pragma warning restore CS8602 // Dereference of a possibly null reference.
228234
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.

src/TimeScheduler/Testing/TestScheduler.Timer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ public void Dispose()
7777
stopTimerCts.Dispose();
7878
}
7979

80+
#if NET6_0_OR_GREATER
8081
public ValueTask DisposeAsync()
8182
{
8283
Dispose();
83-
#if NET6_0_OR_GREATER
8484
return ValueTask.CompletedTask;
85-
#else
86-
return new ValueTask(Task.CompletedTask);
87-
#endif
8885
}
86+
#endif
8987

9088
private void TimerElapsed()
9189
{

src/TimeScheduler/TimeScheduler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
55
<Title>Scheduler</Title>
6-
<Version>0.7.0</Version>
6+
<Version>0.7.1</Version>
77
<Company>Egil Hansen</Company>
88
<Authors>Egil Hansen</Authors>
99
<Description>

test/TimeScheduler.Tests/System/Testing/ManualTimeProviderTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@ public void SetUtcNow_updates_UtcNow()
2323

2424
sut.GetUtcNow().Should().Be(startTime + TimeSpan.FromTicks(1));
2525
}
26+
27+
[Fact]
28+
public void Callbacks_runs_synchronously()
29+
{
30+
// arrange
31+
var sut = new ManualTimeProvider();
32+
var callbackCount = 0;
33+
_ = Continuation(sut, () => callbackCount++);
34+
35+
// act
36+
sut.ForwardTime(TimeSpan.FromSeconds(10));
37+
38+
// assert
39+
callbackCount.Should().Be(1);
40+
41+
static async Task Continuation(TimeProvider timeProvider, Action callback)
42+
{
43+
await timeProvider.Delay(TimeSpan.FromSeconds(10));
44+
callback();
45+
}
46+
}
2647
}

test/TimeScheduler.Tests/System/Testing/ManualTimeProviderWaitAsyncTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if NET6_0_OR_GREATER
12
namespace System.Testing;
23

34
public class ManualTimeProviderWaitAsyncTests
@@ -203,3 +204,4 @@ await task.Awaiting(x => x)
203204
.ThrowExactlyAsync<TaskCanceledException>();
204205
}
205206
}
207+
#endif

test/TimeScheduler.Tests/TimeScheduler.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
5-
<LangVersion>11.0</LangVersion>
5+
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)