Exemplo n.º 1
0
            public bool TryTake(out PrioritizedItem <T> item)
            {
                for (int priority = 0; priority < _itemQueues.Length; priority++)
                {
                    T itemValue;
                    if (_itemQueues[priority].TryDequeue(out itemValue))
                    {
                        item = new PrioritizedItem <T>(itemValue, priority);
                        return(true);
                    }
                }

                item = default(PrioritizedItem <T>);
                return(false);
            }
Exemplo n.º 2
0
        private async Task <T> UnwrapAsync(ValueTask <PrioritizedItem <T> > prioritizedItemTask)
        {
            PrioritizedItem <T> result = await prioritizedItemTask.ConfigureAwait(false);

            return(result.Item);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes and returns an item with the highest priority from the collection in an asynchronous manner.
        /// </summary>
        async Task <T> IAsyncCollection <T> .TakeAsync(System.Threading.CancellationToken cancellationToken)
        {
            PrioritizedItem <T> prioritizedItem = await base.TakeAsync(cancellationToken).ConfigureAwait(false);

            return(prioritizedItem.Item);
        }
Exemplo n.º 4
0
 public bool TryAdd(PrioritizedItem <T> item)
 {
     _itemQueues[item.Priority].Enqueue(item.Item);
     return(true);
 }
Exemplo n.º 5
0
 public bool Equals(PrioritizedItem <T> other) => EqualityComparer <T> .Default.Equals(Item, other.Item) && EqualityComparer <int> .Default.Equals(Priority, other.Priority);