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


C# AsyncQueue.Enqueue方法代码示例

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


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

示例1: Count_nonempty

 public void Count_nonempty()
 {
     var queue = new AsyncQueue<string>();
     queue.Enqueue("A");
     queue.Enqueue("B");
     queue.Enqueue("C");
     queue.Enqueue("D");
     Assert.IsTrue(queue.TryDequeue());
     Assert.AreEqual(3, queue.Count);
 }
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs

示例2: 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

示例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: 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

示例5: 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

示例6: 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

示例7: DequeueAll_should_dequeue_all_items

        public void DequeueAll_should_dequeue_all_items(int n)
        {
            var subject = new AsyncQueue<int>();
            for (var i = 0; i < n; i++)
            {
                subject.Enqueue(i);
            }

            var count = subject.DequeueAll().Count();
            count.Should().Be(n);
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:AsyncQueueTests.cs

示例8: 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

示例9: 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

示例10: TryDequeue

 public void TryDequeue()
 {
     var queue = new AsyncQueue<int>();
     int value;
     Assert.False(queue.TryDequeue(out value));
     queue.Enqueue(13);
     Assert.True(queue.TryDequeue(out value));
     Assert.Equal(13, value);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:9,代码来源:AsyncQueueTests.cs

示例11: DequeueAsyncWithCancellationAfterComplete

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

示例12: CompleteAnyWithCancellationAsync

        private async Task CompleteAnyWithCancellationAsync()
        {
            AsyncQueue<string> q1 = new AsyncQueue<string>(5);
            AsyncQueue<string> q2 = new AsyncQueue<string>(5);

            Func<Task> producer1 = async delegate ()
            {
                await Task.Delay(2500);
                await q1.Enqueue("one", CancellationToken.None);
                q1.WriteEof();
            };

            Func<Task> producer2 = async delegate ()
            {
                await Task.Delay(5500);
                await q2.Enqueue("two", CancellationToken.None);
                q2.WriteEof();
            };

            Func<Task> consumer = async delegate ()
            {
                bool q1eof = false;
                bool q2eof = false;
                while (!q1eof || !q2eof)
                {
                    Tuple<int, string> r1 = null;

                    using (CancellationTokenSource s1 = new CancellationTokenSource(1000))
                    {
                        try
                        {
                            r1 = await Utils.OperationStarters<int, string>()
                                .AddIf(!q1eof, 1, Utils.StartableGet(q1, x => x, null))
                                .AddIf(!q2eof, 2, Utils.StartableGet(q2, x => x, null))
                                .CompleteAny(s1.Token);
                        }
                        catch (OperationCanceledException)
                        {

                        }
                    }

                    if (r1 == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Cancelled (because of timeout)");
                    }
                    else if (r1.Item1 == 1)
                    {
                        if (r1.Item2 == null)
                        {
                            System.Diagnostics.Debug.WriteLine("Got EOF from 1");
                            q1eof = true;
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine($"Got {r1.Item2} from 1");
                        }
                    }
                    else
                    {
                        Assert.AreEqual(2, r1.Item1);
                        if (r1.Item2 == null)
                        {
                            System.Diagnostics.Debug.WriteLine("Got EOF from 2");
                            q2eof = true;
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine($"Got {r1.Item2} from 2");
                        }
                    }
                }
            };

            Task p1 = Task.Run(producer1);
            Task p2 = Task.Run(producer2);
            Task c = Task.Run(consumer);

            await Task.WhenAll(p1, p2, c);
        }
开发者ID:Sunlighter,项目名称:AsyncQueues,代码行数:80,代码来源:AsyncQueueTests.cs

示例13: 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

示例14: DequeueAfterCompleteWithData

        public async Task DequeueAfterCompleteWithData()
        {
            var queue = new AsyncQueue<int>();
            queue.Enqueue(42);
            queue.Complete();
            await queue.WhenCompletedTask.ConfigureAwait(false);
            Assert.Equal(42, await queue.DequeueAsync().ConfigureAwait(false));

            var threw = false;
            try
            {
                await queue.DequeueAsync().ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                threw = true;
            }
            Assert.True(threw);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AsyncQueueTests.cs

示例15: First_in_first_out

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


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