Skip to content

Commit

Permalink
fix(AsyncQueue): use TrySetResult to avoid throwing in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-schlecker committed May 20, 2024
1 parent 2ce90ef commit 43a9e07
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/AsyncQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Enqueue(T item)
WaitWhileLimitReached(cts.Token);
semaphore.Wait();
if (waiters.TryDequeue(out var tcs))
tcs.SetResult(item);
tcs.TrySetResult(item);
else
queue.Enqueue(item);
semaphore.Release();
Expand All @@ -67,7 +67,7 @@ public async Task EnqueueAsync(T item)
await WaitWhileLimitReachedAsync(cts.Token);
await semaphore.WaitAsync();
if (waiters.TryDequeue(out var tcs))
tcs.SetResult(item);
tcs.TrySetResult(item);
else
queue.Enqueue(item);
semaphore.Release();
Expand All @@ -86,7 +86,7 @@ public void EnqueueRange(IEnumerable<T> items)
foreach (var item in items)
{
if (waiters.TryDequeue(out var tcs))
tcs.SetResult(item);
tcs.TrySetResult(item);
else
queue.Enqueue(item);
}
Expand All @@ -106,7 +106,7 @@ public async Task EnqueueRangeAsync(IEnumerable<T> items)
foreach (var item in items)
{
if (waiters.TryDequeue(out var tcs))
tcs.SetResult(item);
tcs.TrySetResult(item);
else
queue.Enqueue(item);
}
Expand Down

0 comments on commit 43a9e07

Please sign in to comment.