Skip to content

Commit a90f0ab

Browse files
authored
Make ThreadingUtilities.ExecuteTasksOnNewThreads await on the operation completion. (#1275)
1 parent 13d89ef commit a90f0ab

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/MongoDB.Bson.TestHelpers/Threading/TasksUtils.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public static Task<T>[] CreateTasksOnOwnThread<T>(int count, Func<int, T> functi
4545
new ThreadPerTaskScheduler()))
4646
.ToArray();
4747

48+
public static Task[] RunTasksOnOwnThread(int count, Func<int, Task> taskCreator, CancellationToken cancellationToken = default) =>
49+
Enumerable.Range(0, count)
50+
.Select(i => Task.Factory.StartNew(
51+
() => taskCreator(i),
52+
cancellationToken,
53+
TaskCreationOptions.None,
54+
new ThreadPerTaskScheduler()).Unwrap())
55+
.ToArray();
56+
4857
public static Task<T>[] CreateTasks<T>(int count, Func<int, Task<T>> taskCreator) =>
4958
Enumerable.Range(0, count)
5059
.Select(i => taskCreator(i))

tests/MongoDB.Bson.TestHelpers/Threading/ThreadingUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static async Task<Exception[]> ExecuteTasksOnNewThreadsCollectExceptions(
9292
var exceptions = new ConcurrentBag<Exception>();
9393
var tasksExecutingCountEvent = new CountdownEvent(threadsCount);
9494

95-
var allTasks = TasksUtils.CreateTasksOnOwnThread(threadsCount, async i =>
95+
var allTasks = TasksUtils.RunTasksOnOwnThread(threadsCount, async i =>
9696
{
9797
try
9898
{

0 commit comments

Comments
 (0)