Skip to content

Commit

Permalink
AsyncAutoResetEvent enhancement (#35593)
Browse files Browse the repository at this point in the history
- Use Task.CompltedTask
- Let class sealed
  • Loading branch information
WeihanLi authored Jul 17, 2023
1 parent a5d3211 commit 9a33101
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sdk/openai/Azure.AI.OpenAI/src/Helpers/AsyncAutoResetEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
namespace Azure.AI.OpenAI
{
// Adapted from https://devblogs.microsoft.com/pfxteam/building-async-coordination-primitives-part-2-asyncautoresetevent/
internal class AsyncAutoResetEvent
internal sealed class AsyncAutoResetEvent
{
private static readonly Task s_completed = Task.FromResult(true);
private readonly Queue<TaskCompletionSource<bool>> _waits = new Queue<TaskCompletionSource<bool>>();
private bool _signaled;

Expand All @@ -21,7 +20,7 @@ public Task WaitAsync(CancellationToken cancellationToken = default)
if (_signaled)
{
_signaled = false;
return s_completed;
return Task.CompletedTask;
}
else
{
Expand Down

0 comments on commit 9a33101

Please sign in to comment.