Skip to content

Commit b980fa3

Browse files
committed
Made Context parameter nullable
Fixed unit tests
1 parent 39cf588 commit b980fa3

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

DispatchQueue/IDispatchQueue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace Dispatch
88
{
99
public interface IDispatchQueue
1010
{
11-
public void DispatchAsync(object context, WaitCallback work);
11+
public void DispatchAsync(object? context, WaitCallback work);
1212
}
1313

1414

1515
public static class IDispatchQueueExtensionMethods
1616
{
17-
public static void DispatchSync(this IDispatchQueue queue, object context, WaitCallback? work)
17+
public static void DispatchSync(this IDispatchQueue queue, object? context, WaitCallback? work)
1818
{
1919
TaskCompletionSource<object?> tcs = new TaskCompletionSource<object?>();
2020

DispatchQueue/SerialQueue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SerialQueue : IDispatchQueue
1515
private struct WorkData
1616
{
1717
public WaitCallback Work;
18-
public object Context;
18+
public object? Context;
1919
}
2020

2121
private readonly IThreadPool mThreadPool;
@@ -41,7 +41,7 @@ public SerialQueue(IThreadPool threadPool)
4141
///
4242
/// </summary>
4343
/// <param name="task"></param>
44-
public void DispatchAsync(object context, WaitCallback work)
44+
public void DispatchAsync(object? context, WaitCallback work)
4545
{
4646
// can't allow nulls in our queue
4747
if (work == null)

Tests/SerialQueueTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void AsyncRunsOnSeparateThreads()
2121

2222
for (int i = 0; i < 10; ++i)
2323
{
24-
queue.DispatchAsync(() =>
24+
queue.DispatchAsync(null, (_) =>
2525
{
2626
Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId);
2727
});
@@ -37,7 +37,7 @@ public void SyncRunsOnSeparateThreads()
3737

3838
for (int i = 0; i < 10; ++i)
3939
{
40-
queue.DispatchSync(() =>
40+
queue.DispatchSync(null, (_) =>
4141
{
4242
Assert.AreNotEqual(threadId, Thread.CurrentThread.ManagedThreadId);
4343
});
@@ -53,7 +53,7 @@ public void SyncRunsSynchronously()
5353

5454
for (int i = 0; i < 100; ++i)
5555
{
56-
queue.DispatchSync(() =>
56+
queue.DispatchSync(null, (_) =>
5757
{
5858
Assert.AreEqual(numberTest++, i);
5959
});
@@ -70,7 +70,7 @@ public void TasksRunOneAtATime()
7070

7171
for (int i = 0; i < 10; ++i)
7272
{
73-
queue.DispatchAsync(() =>
73+
queue.DispatchAsync(null, (_) =>
7474
{
7575
Assert.IsFalse(taskRunning);
7676
taskRunning = true;
@@ -82,7 +82,7 @@ public void TasksRunOneAtATime()
8282
});
8383
}
8484

85-
queue.DispatchSync(() =>
85+
queue.DispatchSync(null, (_) =>
8686
{
8787
// just to ensure that the tests don't finish prematurely.
8888
});
@@ -99,13 +99,13 @@ public void TasksCompletedInProperSequence()
9999
for (int i = 0; i < 100; ++i)
100100
{
101101
int localValue = i;
102-
queue.DispatchAsync(() =>
102+
queue.DispatchAsync(null, (_) =>
103103
{
104104
Assert.AreEqual(numberTest++, localValue);
105105
});
106106
}
107107

108-
queue.DispatchSync(() =>
108+
queue.DispatchSync(null, (_) =>
109109
{
110110
Assert.AreEqual(numberTest, 100);
111111
});

0 commit comments

Comments
 (0)