当前位置: 首页>>代码示例>>C#>>正文


C# AsyncQueue.DequeueAsync方法代码示例

本文整理汇总了C#中AsyncQueue.DequeueAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue.DequeueAsync方法的具体用法?C# AsyncQueue.DequeueAsync怎么用?C# AsyncQueue.DequeueAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AsyncQueue的用法示例。


在下文中一共展示了AsyncQueue.DequeueAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Items_should_be_dequeued_in_the_order_they_were_enqueued_2

        public void Items_should_be_dequeued_in_the_order_they_were_enqueued_2()
        {
            var subject = new AsyncQueue<int>();
            var result = subject.DequeueAsync(CancellationToken.None);
            var result2 = subject.DequeueAsync(CancellationToken.None);
            subject.Enqueue(10);
            subject.Enqueue(11);

            result.Result.Should().Be(10);
            result2.Result.Should().Be(11);
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:AsyncQueueTests.cs

示例2: Dequeue_should_return_an_uncompleted_task_when_no_items_exist

        public void Dequeue_should_return_an_uncompleted_task_when_no_items_exist()
        {
            var subject = new AsyncQueue<int>();
            var result = subject.DequeueAsync(CancellationToken.None);

            result.IsCompleted.Should().BeFalse();
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:7,代码来源:AsyncQueueTests.cs

示例3: DequeueAsync_before_Enqueue

 public void DequeueAsync_before_Enqueue()
 {
     var queue = new AsyncQueue<string>();
     var task = queue.DequeueAsync().AssertNotCompleted();
     queue.Enqueue("A");
     task.AssertResult("A");
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:7,代码来源:AsyncQueueTests.cs

示例4: Dequeue_should_complete_when_an_item_is_added_to_the_queue

        public void Dequeue_should_complete_when_an_item_is_added_to_the_queue()
        {
            var subject = new AsyncQueue<int>();
            var result = subject.DequeueAsync(CancellationToken.None);
            subject.Enqueue(10);

            result.Result.Should().Be(10);
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:8,代码来源:AsyncQueueTests.cs

示例5: Enqueue

 public void Enqueue()
 {
     var queue = new AsyncQueue<int>();
     queue.Enqueue(42);
     var task = queue.DequeueAsync();
     Assert.True(task.IsCompleted);
     Assert.Equal(42, task.Result);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:AsyncQueueTests.cs

示例6: DequeueThenEnqueue

 public async Task DequeueThenEnqueue()
 {
     var queue = new AsyncQueue<int>();
     var task = queue.DequeueAsync();
     Assert.False(task.IsCompleted);
     queue.Enqueue(13);
     Assert.Equal(13, await task.ConfigureAwait(false));
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:AsyncQueueTests.cs

示例7: AsyncQueueSkipsCancelledTasks

        public async Task AsyncQueueSkipsCancelledTasks()
        {
            AsyncQueue<int> inputQueue = new AsyncQueue<int>();

            // Queue up a couple of tasks to wait for input
            CancellationTokenSource cancellationSource = new CancellationTokenSource();
            Task<int> taskOne = inputQueue.DequeueAsync(cancellationSource.Token);
            Task<int> taskTwo = inputQueue.DequeueAsync();

            // Cancel the first task and then enqueue a number
            cancellationSource.Cancel();
            await inputQueue.EnqueueAsync(1);

            // Did the second task get the number?
            Assert.Equal(TaskStatus.Canceled, taskOne.Status);
            Assert.Equal(TaskStatus.RanToCompletion, taskTwo.Status);
            Assert.Equal(1, taskTwo.Result);
        }
开发者ID:sunnyc7,项目名称:PowerShellEditorServices,代码行数:18,代码来源:AsyncQueueTests.cs

示例8: VerifyEvents

        internal static void VerifyEvents(AsyncQueue<CompilationEvent> queue, params string[] expectedEvents)
        {
            var expected = new HashSet<string>();
            foreach (var s in expectedEvents)
            {
                if (!expected.Add(s))
                {
                    Console.WriteLine("Expected duplicate " + s);
                }
            }

            var actual = ArrayBuilder<CompilationEvent>.GetInstance();
            while (queue.Count > 0 || !queue.IsCompleted)
            {
                var te = queue.DequeueAsync();
                Assert.True(te.IsCompleted);
                actual.Add(te.Result);
            }
            bool unexpected = false;
            foreach (var a in actual)
            {
                var eventString = a.ToString();
                if (!expected.Remove(eventString))
                {
                    if (!unexpected)
                    {
                        Console.WriteLine("UNEXPECTED EVENTS:");
                        unexpected = true;
                    }
                    Console.WriteLine(eventString);
                }
            }
            if (expected.Count != 0)
            {
                Console.WriteLine("MISSING EVENTS:");
            }
            foreach (var e in expected)
            {
                Console.WriteLine(e);
            }
            if (unexpected || expected.Count != 0)
            {
                bool first = true;
                Console.WriteLine("ACTUAL EVENTS:");
                foreach (var e in actual)
                {
                    if (!first)
                    {
                        Console.WriteLine(",");
                    }
                    first = false;
                    Console.Write("\"" + e.ToString() + "\"");
                }
                Console.WriteLine();
                Assert.True(false);
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:57,代码来源:CompilationEventTests.cs

示例9: CancelAllDequeue

 public void CancelAllDequeue()
 {
     var queue = new AsyncQueue<string>();
     var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
     queue.CancelAllDequeue().Dispose();
     foreach (var task in tasks)
     {
         task.AssertCanceled();
     }
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs

示例10: CompleteAllDequeue

 public void CompleteAllDequeue()
 {
     var queue = new AsyncQueue<string>();
     var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
     queue.CompleteAllDequeue("X").Dispose();
     foreach (var task in tasks)
     {
         task.AssertResult("X");
     }
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs

示例11: ConsumeItems

 private async Task ConsumeItems(
     AsyncQueue<int> inputQueue,
     ConcurrentBag<int> outputItems,
     CancellationToken cancellationToken)
 {
     while (!cancellationToken.IsCancellationRequested)
     {
         int consumedItem = await inputQueue.DequeueAsync(cancellationToken);
         outputItems.Add(consumedItem);
     }
 }
开发者ID:sunnyc7,项目名称:PowerShellEditorServices,代码行数:11,代码来源:AsyncQueueTests.cs

示例12: DequeueAsync_canceled_after_completion

 public void DequeueAsync_canceled_after_completion()
 {
     var queue = new AsyncQueue<string>();
     queue.Enqueue("A");
     using (var cts = new CancellationTokenSource())
     {
         var task = queue.DequeueAsync(cts.Token);
         cts.Cancel();
         task.AssertResult("A");
     }
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:11,代码来源:AsyncQueueTests.cs

示例13: DequeueThenComplete

        public async Task DequeueThenComplete()
        {
            var queue = new AsyncQueue<int>();
            var task = queue.DequeueAsync();
            Assert.False(task.IsCompleted);

            queue.Complete();
            var threw = false;
            try
            {
                await task.ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                threw = true;
            }

            Assert.True(threw);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AsyncQueueTests.cs

示例14: DequeueManyThenEnqueueMany

        public async Task DequeueManyThenEnqueueMany()
        {
            var queue = new AsyncQueue<int>();
            var count = 4;
            var list = new List<Task<int>>();

            for (var i = 0; i < count; i++)
            {
                list.Add(queue.DequeueAsync());
            }

            for (var i = 0; i < count; i++)
            {
                var task = list[i];
                Assert.False(task.IsCompleted);
                queue.Enqueue(i);
                Assert.Equal(i, await task.ConfigureAwait(false));
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AsyncQueueTests.cs

示例15: DequeueAsync_handled_in_order_of_caller

 public void DequeueAsync_handled_in_order_of_caller()
 {
     var queue = new AsyncQueue<string>();
     var values = new List<string> { "A", "B", "C" };
     var tasks = values.Select(_ => queue.DequeueAsync()).ToList();
     for (int i = 0; i < values.Count; i++)
     {
         tasks[i].AssertNotCompleted();
         queue.Enqueue(values[i]);
         tasks[i].AssertResult(values[i]);
     }
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:12,代码来源:AsyncQueueTests.cs


注:本文中的AsyncQueue.DequeueAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。