1 // -----------------------------------------------------------------------
2 // <copyright file="AsyncAutoResetEvent.cs" company="Microsoft">
3 // TODO: Update copyright text.
5 // -----------------------------------------------------------------------
7 using System.Threading.Tasks;
9 namespace Pithos.Core.Agents
12 using System.Collections.Generic;
17 /// TODO: Update summary.
19 public class AsyncAutoResetEvent
21 private readonly static Task Completed = TaskEx.FromResult(true);
22 private readonly Queue<TaskCompletionSource<bool>> _waits = new Queue<TaskCompletionSource<bool>>();
23 private bool _signaled;
25 public Task WaitAsync()
36 var tcs = new TaskCompletionSource<bool>();
45 TaskCompletionSource<bool> toRelease = null;
49 toRelease = _waits.Dequeue();
53 if (toRelease != null)
54 toRelease.SetResult(true);