Beispiel #1
0
        Task <T> IAsyncWaitQueue <T> .Enqueue()
        {
            var tcs = TaskCompletionSourceExtensions.CreateAsyncTaskSource <T>();

            _queue.AddToBack(tcs);
            return(tcs.Task);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncManualResetEventSlim"/> class with a Boolean value indicating whether to set the initial state to signaled.
 /// </summary>
 /// <param name="initialState">true to set the initial state signaled; false to set the initial state to nonSignaled.</param>
 public AsyncManualResetEventSlim(bool initialState)
 {
     _tcs = TaskCompletionSourceExtensions.CreateAsyncTaskSource <bool>();
     if (initialState)
     {
         _tcs.SetResult(true);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Creates an async-compatible manual-reset event.
 /// </summary>
 /// <param name="set">Whether the manual-reset event is initially set or unset.</param>
 public AsyncManualResetEvent(bool set)
 {
     _mutex = new object();
     _tcs   = TaskCompletionSourceExtensions.CreateAsyncTaskSource <object>();
     if (set)
     {
         _tcs.TrySetResult(null);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Resets the event. If the event is already reset, this method does nothing.
 /// </summary>
 public void Reset()
 {
     lock (_mutex)
     {
         if (_tcs.Task.IsCompleted)
         {
             _tcs = TaskCompletionSourceExtensions.CreateAsyncTaskSource <object>();
         }
     }
 }
 Task<T> IAsyncWaitQueue<T>.Enqueue()
 {
     TaskCompletionSource<T> taskCompletionSource = TaskCompletionSourceExtensions.CreateAsyncTaskSource<T>();
     _queue.AddToBack(taskCompletionSource);
     return taskCompletionSource.Task;
 }