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


C# Channel.SubscribeToBatch方法代码示例

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


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

示例1: Batching

        public void Batching()
        {
            using (var fiber = new ThreadFiber())
            {
                fiber.Start();
                var counter = new Channel<int>();
                var reset = new ManualResetEvent(false);
                var total = 0;
                Action<IList<int>> cb = delegate(IList<int> batch)
                                            {
                                                total += batch.Count;
                                                if (total == 10)
                                                {
                                                    reset.Set();
                                                }
                                            };

                counter.SubscribeToBatch(fiber, cb, 1);

                for (var i = 0; i < 10; i++)
                {
                    counter.Publish(i);
                }

                Assert.IsTrue(reset.WaitOne(10000, false));
            }
        }
开发者ID:GWBasic,项目名称:retlang,代码行数:27,代码来源:BasicExamples.cs

示例2: TestBatching

 public static void TestBatching(IFiber fiber)
 {
     using (fiber)
     using (var reset = new ManualResetEvent(false))
     {
         var counter = new Channel<int>();
         int total = 0;
         Action<IList<int>> cb = batch =>
         {
             total += batch.Count;
             if (total == 10)
                 reset.Set();
         };
         counter.SubscribeToBatch(fiber, cb, TimeSpan.FromMilliseconds(1));
         for (int i = 0; i < 10; i++)
             counter.Publish(i);
         Assert.IsTrue(reset.WaitOne(10000, false));
     }
 }
开发者ID:JackWangCUMT,项目名称:Fibrous,代码行数:19,代码来源:FiberTester.cs

示例3: MyOwnBatchingTestToMakeSureIUnderstandRetlangsBatchingStuff

        public void MyOwnBatchingTestToMakeSureIUnderstandRetlangsBatchingStuff()
        {
            using (var fiber = new PoolFiber())
            {
                fiber.Start();
                var reset = new ManualResetEvent(false);

                var channel = new Channel<BatchTestMessage>();
                channel.SubscribeToBatch(fiber, BatchSubscriberMethod, 1);

                for(var i=0; i < 10; i++) // <---  increase to 1000000 or so to see it make 3 or 4 calls to BatchSubscriber!
                {
                    channel.Publish(new BatchTestMessage("loop " + i));
                }

                //Assert.IsTrue(reset.WaitOne(10000, false));

                reset.WaitOne(1000, false);
            }
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:20,代码来源:RetlangTest.cs

示例4: SubToBatch

        public void SubToBatch()
        {
            Channel<string> channel = new Channel<string>();
            StubCommandContext queue = new StubCommandContext();
            bool received = false;
            Action<IList<string>> onReceive = delegate(IList<string> data)
                                                  {
                                                      Assert.AreEqual(5, data.Count);
                                                      Assert.AreEqual("0", data[0]);
                                                      Assert.AreEqual("4", data[4]);
                                                      received = true;
                                                  };
            channel.SubscribeToBatch(queue, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(i.ToString());
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            queue.Scheduled.Clear();
            received = false;

            channel.Publish("5");
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
        }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:28,代码来源:ChannelTests.cs


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