Skip to content

Commit 57c88bc

Browse files
committed
Modified WaitForQueueToEndAsync
1 parent 19c2c00 commit 57c88bc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/ZirconNet.Core/Async/AsyncTaskQueue.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class AsyncTaskQueue
1212
private SemaphoreSlim _taskSemaphore;
1313
private SemaphoreSlim _queueSemaphore;
1414
private int _tasksInQueue = 0;
15-
private readonly ConcurrentBag<Exception> _exceptions = new ();
15+
private readonly ConcurrentBag<Exception> _exceptions = new();
1616

1717
public bool IsFaulted { get; private set; } = false;
1818

@@ -66,14 +66,17 @@ public async Task AddTaskAsync(Func<Task> actionToRun, CancellationToken cancell
6666
}
6767
}
6868

69-
public async Task WaitForQueueToEndAsync(CancellationToken cancellationToken = default)
69+
public async ValueTask WaitForQueueToEndAsync(CancellationToken cancellationToken = default)
7070
{
71-
await _queueSemaphore.WaitAsync(cancellationToken);
71+
if (_tasksInQueue > 0)
72+
{
73+
await _queueSemaphore.WaitAsync(cancellationToken);
74+
}
7275
}
7376

7477
public async ValueTask Reset(int maximumThreads = -1)
7578
{
76-
if (_tasksInQueue is not 0)
79+
if (_tasksInQueue > 0)
7780
{
7881
await WaitForQueueToEndAsync();
7982
}

0 commit comments

Comments
 (0)