Пример #1
0
 private void LockedUpdateEnqueueAccess()
 {
     for (int i = ItemsQueue.Count; EnqueueAccess.Count > 0 && (ThrottleLevelLimiter == null || i < ThrottleLevelLimiter); i++)
     {
         TaskCompletionSource <object> tcs = EnqueueAccess.Dequeue();
         tcs?.SetResult(null);
     }
 }
Пример #2
0
        private Task LockedInsertUpdateAsync()
        {
            int maxConsumers = Math.Min(ItemsQueue.Count, DequeueAccess.Count);

            while (maxConsumers-- > 0)
            {
                TaskCompletionSource <object> tcs = DequeueAccess.Dequeue();
                tcs?.SetResult(null);
            }

            if (ThrottleLevelLimiter == null || ThrottleLevelLimiter.Value > ItemsQueue.Count)
            {
                return(Task.CompletedTask);
            }
            var tcs2 = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

            EnqueueAccess.Enqueue(tcs2);
            return(tcs2.Task);
        }