Пример #1
0
 public async Task CompleteAddingAsync()
 {
     using (await _mutex.LockAsync().ConfigureAwait(false))
     {
         if (_completed.IsCancellationRequested)
         {
             return;
         }
         _completed.Cancel();
         _completedOrNotEmpty.NotifyAll();
     }
 }
Пример #2
0
 /// <summary>
 /// Sends a signal to all tasks waiting on this monitor. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns.
 /// </summary>
 public void PulseAll()
 {
     _conditionVariable.NotifyAll();
 }
        public void MultipleWaits_NotifyAll_AllAreCompleted()
        {
            Test.Async(async () =>
            {
                var mutex = new AsyncLock();
                var cv = new AsyncConditionVariable(mutex);
                var key1 = await mutex.LockAsync();
                var task1 = cv.WaitAsync();
                var __ = task1.ContinueWith(_ => key1.Dispose());
                var key2 = await mutex.LockAsync();
                var task2 = cv.WaitAsync();
                var ___ = task2.ContinueWith(_ => key2.Dispose());

                await TaskShim.Run(async () =>
                {
                    using (await mutex.LockAsync())
                    {
                        cv.NotifyAll();
                    }
                });
            
                await task1;
                await task2;
            });
        }