Skip to content

Commit 164eb1b

Browse files
committed
Remove IIntervalTimer and ScheduleOnInterval.
1 parent 5b233f9 commit 164eb1b

File tree

11 files changed

+46
-304
lines changed

11 files changed

+46
-304
lines changed

src/AsyncFiberWorks/Timers/IntervalThreadingTimer.cs renamed to src/AsyncFiberWorks.Windows/Timer/IntervalThreadingTimer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using AsyncFiberWorks.Core;
2-
using System;
1+
using System;
32
using System.Threading;
43

5-
namespace AsyncFiberWorks.Timers
4+
namespace AsyncFiberWorks.Windows.Timers
65
{
76
/// <summary>
87
/// Wrapper class for System.Threading.Timer.
98
/// </summary>
10-
public class IntervalThreadingTimer : IIntervalTimer, IDisposable
9+
public class IntervalThreadingTimer : IDisposable
1110
{
1211
readonly object _lockObj = new object();
1312
readonly Timer _timer;

src/AsyncFiberWorks.Windows/Timer/IntervalWaitableTimerEx.cs

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/AsyncFiberWorks.Windows/Timer/WaitableTimerEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.InteropServices;
55
using System.Threading;
66

7-
namespace AsyncFiberWorks.Windows.Timer
7+
namespace AsyncFiberWorks.Windows.Timers
88
{
99
/// <summary>
1010
/// Waitable timer with CREATE_WAITABLE_TIMER_HIGH_RESOLUTION.

src/AsyncFiberWorks.Windows/Timer/WaitableTimerSleeper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Threading;
33

4-
namespace AsyncFiberWorks.Windows.Timer
4+
namespace AsyncFiberWorks.Windows.Timers
55
{
66
/// <summary>
77
/// Sleep implements using WaitableTimerEx in Windows.

src/AsyncFiberWorks/Core/IIntervalTimer.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/AsyncFiberWorks/Timers/TimerExtensions.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/AsyncFiberWorksTests/ConcurrentQueueActionQueueTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void ScheduledTasksShouldBeExecutedOnceScheduleIntervalShouldBeExecutedEv
4747
var subscriptions = new Subscriptions();
4848
var queue = new ConcurrentQueueActionQueue();
4949
var fiber = new PoolFiber(new ThreadPoolAdapter(queue));
50-
var timer2 = new IntervalThreadingTimer();
5150

5251
var scheduleFired = 0;
5352
var scheduleOnIntervalFired = 0;
@@ -60,7 +59,16 @@ public void ScheduledTasksShouldBeExecutedOnceScheduleIntervalShouldBeExecutedEv
6059
});
6160
var subscriptionFiber = subscriptions.BeginSubscription();
6261
var cancellation = new CancellationTokenSource();
63-
timer2.ScheduleOnInterval(fiber, () => scheduleOnIntervalFired++, 100, 500, cancellation.Token);
62+
var token = cancellation.Token;
63+
_ = Task.Run(async () =>
64+
{
65+
await Task.Delay(100, token);
66+
while (!cancellation.Token.IsCancellationRequested)
67+
{
68+
fiber.Enqueue(() => scheduleOnIntervalFired++);
69+
await Task.Delay(500, token);
70+
}
71+
});
6472
subscriptionFiber.AppendDisposable(cancellation);
6573

6674
// add to the pending list.
@@ -79,7 +87,6 @@ public void ScheduledTasksShouldBeExecutedOnceScheduleIntervalShouldBeExecutedEv
7987
Assert.AreEqual(2, scheduleOnIntervalFired);
8088

8189
subscriptionFiber.Dispose();
82-
timer2.Dispose();
8390

8491
// The regularInMs has passed after dispose.
8592
Thread.Sleep(500);

src/AsyncFiberWorksTests/FiberAsyncContextTests.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,6 @@ public async Task EnqueueTest(Func<IFiber> fiberCreator)
7676
Assert.AreEqual(120, counter);
7777
}
7878

79-
[Test]
80-
[TestCaseSource(typeof(MyDataClass), nameof(MyDataClass.AllFibers))]
81-
public async Task RepeatingTimer(Func<IFiber> fiberCreator)
82-
{
83-
var fiber = fiberCreator();
84-
var timer = new IntervalThreadingTimer();
85-
86-
var sw = Stopwatch.StartNew();
87-
int counter = 0;
88-
timer.ScheduleOnInterval(fiber, async () =>
89-
{
90-
await Task.Yield();
91-
counter += 1;
92-
Console.WriteLine($"cb{sw.Elapsed}");
93-
}, 250, 500);
94-
Console.WriteLine($"as{sw.Elapsed}");
95-
Assert.AreEqual(0, counter);
96-
await Task.Delay(500).ConfigureAwait(false);
97-
Console.WriteLine($"as{sw.Elapsed}");
98-
Assert.AreEqual(1, counter);
99-
await Task.Delay(500).ConfigureAwait(false);
100-
Console.WriteLine($"as{sw.Elapsed}");
101-
Assert.AreEqual(2, counter);
102-
await Task.Delay(500).ConfigureAwait(false);
103-
Console.WriteLine($"as{sw.Elapsed}");
104-
Assert.AreEqual(3, counter);
105-
timer.Dispose();
106-
await Task.Delay(500).ConfigureAwait(false);
107-
Console.WriteLine($"as{sw.Elapsed}");
108-
Assert.AreEqual(3, counter);
109-
timer.Dispose();
110-
}
111-
11279
[Test]
11380
[TestCaseSource(typeof(MyDataClass), nameof(MyDataClass.AllFibers))]
11481
public async Task EnqueueTaskAsyncTest(Func<IFiber> fiberCreator)

src/AsyncFiberWorksTests/TimerActionTests.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using AsyncFiberWorks.Core;
21
using AsyncFiberWorks.Fibers;
3-
using AsyncFiberWorks.Timers;
4-
using AsyncFiberWorks.Windows.Timer;
2+
using AsyncFiberWorks.Windows.Timers;
53
using NUnit.Framework;
64
using System;
75
using System.Threading;
@@ -12,10 +10,10 @@ namespace AsyncFiberWorksTests
1210
[TestFixture]
1311
public class TimerActionTests
1412
{
15-
[Test, TestCaseSource(nameof(IntervalTimers))]
16-
public void CallbackFromIntervalTimerWithCancel(Func<IIntervalTimer> timerCreator)
13+
[Test]
14+
public void CallbackFromIntervalTimerWithCancel()
1715
{
18-
var timer = timerCreator();
16+
var timer = new IntervalThreadingTimer();
1917
var fiber = new PoolFiber();
2018
long counterOnTimer = 0;
2119
Action actionOnTimer = () => { counterOnTimer++; };
@@ -43,14 +41,6 @@ public void CallbackFromIntervalTimerWithCancel(Func<IIntervalTimer> timerCreato
4341
timer.Dispose();
4442
}
4543

46-
static object[] IntervalTimers =
47-
{
48-
new object[] { (Func<IIntervalTimer>)(() => new IntervalThreadingTimer()) },
49-
#if NETFRAMEWORK || WINDOWS
50-
new object[] { (Func<IIntervalTimer>)(() => new IntervalWaitableTimerEx()) },
51-
#endif
52-
};
53-
5444
#if NETFRAMEWORK || WINDOWS
5545
[Test]
5646
public async Task CancelWaitableTimer()

0 commit comments

Comments
 (0)