Skip to content

Commit c4b4ba2

Browse files
committed
Fixed awaiting task
1 parent 4d3c831 commit c4b4ba2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/NetMQ.Tests/NetMQPollerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ public void TwoThreads()
984984

985985
TaskUtils.Wait(t1, TimeSpan.FromMilliseconds(1000));
986986
TaskUtils.Wait(t2, TimeSpan.FromMilliseconds(1000));
987-
TaskUtils.WaitAll(allTasks.ToArray(), TimeSpan.FromMilliseconds(1000));
987+
TaskUtils.WaitAll(allTasks, TimeSpan.FromMilliseconds(1000));
988988

989989
Assert.Equal(100, count1);
990990
Assert.Equal(100, count2);

src/NetMQ.Tests/TaskUtils.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Threading;
45
using System.Threading.Tasks;
@@ -30,24 +31,26 @@ internal static async Task PollUntil(Func<bool> condition, CancellationToken ct
3031
}
3132
}
3233

33-
internal static bool WaitAll(Task[] tasks, TimeSpan timeout)
34+
internal static bool WaitAll(IEnumerable<Task> tasks, TimeSpan timeout)
3435
{
35-
return PollUntil(() => tasks.All(t => t.IsCompleted), timeout).Status == TaskStatus.RanToCompletion;
36+
PollUntil(() => tasks.All(t => t.IsCompleted), timeout).Wait();
37+
return tasks.All(t => t.Status == TaskStatus.RanToCompletion);
3638
}
3739

38-
internal static bool WaitAll(Task[] tasks)
40+
internal static void WaitAll(IEnumerable<Task> tasks)
3941
{
40-
return WaitAll(tasks, TimeSpan.MaxValue);
42+
PollUntil(() => tasks.All(t => t.IsCompleted), Timeout.InfiniteTimeSpan).Wait();
4143
}
4244

4345
internal static bool Wait(Task task, TimeSpan timeout)
4446
{
45-
return PollUntil(() => task.IsCompleted, timeout).Status == TaskStatus.RanToCompletion;
47+
PollUntil(() => task.IsCompleted, timeout).Wait();
48+
return task.Status == TaskStatus.RanToCompletion;
4649
}
4750

48-
internal static bool Wait(Task task)
51+
internal static void Wait(Task task)
4952
{
50-
return Wait(task, TimeSpan.MaxValue);
53+
PollUntil(() => task.IsCompleted, Timeout.InfiniteTimeSpan).Wait();
5154
}
5255
}
5356
}

0 commit comments

Comments
 (0)