コード例 #1
0
        /// <summary>
        /// Retrieves the item at the head of the queue, and returns a queue with the head element removed.
        /// </summary>
        /// <typeparam name="T">The type of elements stored in the queue.</typeparam>
        /// <param name="queue">The queue to dequeue from.</param>
        /// <param name="value">Receives the value from the head of the queue.</param>
        /// <returns>The new queue with the head element removed.</returns>
        /// <exception cref="InvalidOperationException">Thrown when the stack is empty.</exception>
        public static IImmutableQueue <T> Dequeue <T>(this IImmutableQueue <T> queue, out T value)
        {
            Requires.NotNull(queue, nameof(queue));

            value = queue.Peek();
            return(queue.Dequeue());
        }
コード例 #2
0
ファイル: AsyncStateMachine.cs プロジェクト: arlm/LiquidState
        private async Task ProcessQueueInternal()
        {
            // Always yield if the task was queued.
            await Task.Yield();

            queueMonitor.Enter();
            try
            {
                while (queueCount > 0)
                {
                    var current = actionsQueue.Peek();
                    actionsQueue = actionsQueue.Dequeue();
                    queueCount--;
                    queueMonitor.Exit();

                    try
                    {
                        if (current != null)
                        {
                            await current();
                        }
                    }
                    finally
                    {
                        queueMonitor.Enter();
                    }
                }
            }
            finally
            {
                // Exit monitor regardless of this method entering the monitor.
                machine.Monitor.Exit();
                queueMonitor.Exit();
            }
        }
コード例 #3
0
        public void DeserializeQueueInterface()
        {
            string json = @"[
  ""One"",
  ""II"",
  ""3""
]";

            IImmutableQueue <string> data = JsonSerializer.Deserialize <IImmutableQueue <string> >(json);

            Assert.False(data.IsEmpty);
            Assert.Equal("One", data.Peek());
            data = data.Dequeue();
            Assert.Equal("II", data.Peek());
            data = data.Dequeue();
            Assert.Equal("3", data.Peek());
        }
コード例 #4
0
        public void EnqueueDequeueTest()
        {
            this.EnqueueDequeueTestHelper(new GenericParameterHelper(1), new GenericParameterHelper(2), new GenericParameterHelper(3));
            this.EnqueueDequeueTestHelper <GenericParameterHelper>();

            // interface test
            IImmutableQueue <GenericParameterHelper> queueInterface          = ImmutableQueue.Create <GenericParameterHelper>();
            IImmutableQueue <GenericParameterHelper> populatedQueueInterface = queueInterface.Enqueue(new GenericParameterHelper(5));

            Assert.Equal(new GenericParameterHelper(5), populatedQueueInterface.Peek());
        }
コード例 #5
0
 public static Option <T> peek <T>(IImmutableQueue <T> queue)
 {
     try
     {
         return(Some(queue.Peek()));
     }
     catch (InvalidOperationException)
     {
         return(None);
     }
 }
コード例 #6
0
ファイル: ImmutableQueue2.cs プロジェクト: cs130-w21/13
 public static IImmutableQueue <T> Dequeue <T>(
     this IImmutableQueue <T> queue,
     out T value)
 {
     if (queue == null)
     {
         throw new ArgumentNullException(nameof(queue));
     }
     value = queue.Peek();
     return(queue.Dequeue());
 }
コード例 #7
0
        private void RunFromQueueIfNotEmpty()
        {
            isRunning = true;
            isInQueue = true;

            while (queueCount > 0)
            {
                Action current = null;
                lock (actionsQueue)
                {
                    current      = actionsQueue.Peek();
                    actionsQueue = actionsQueue.Dequeue();
                    queueCount--;
                }
                current();
            }

            isInQueue = false;
            isRunning = false;
        }
コード例 #8
0
 public static T peekUnsafe <T>(IImmutableQueue <T> queue) =>
 queue.Peek();