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


C# Channel.SubscribeToKeyedBatch方法代码示例

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


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

示例1: BatchingWithKey

        public void BatchingWithKey()
        {
            using (var fiber = new ThreadFiber())
            {
                fiber.Start();
                var counter = new Channel<int>();
                var reset = new ManualResetEvent(false);
                Action<IDictionary<String, int>> cb = delegate(IDictionary<String, int> batch)
                {
                    if (batch.ContainsKey("9"))
                    {
                        reset.Set();
                    }
                };

                Converter<int, String> keyResolver = x => x.ToString();
                counter.SubscribeToKeyedBatch<int, String>(fiber, cb, keyResolver, 0);

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

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

示例2: TestBatchingWithKey

 public static void TestBatchingWithKey(IFiber fiber)
 {
     using (fiber)
     using (var reset = new ManualResetEvent(false))
     {
         var counter = new Channel<int>();
         Action<IDictionary<String, int>> cb = batch =>
         {
             if (batch.ContainsKey("9"))
                 reset.Set();
         };
         Converter<int, String> keyResolver = x => x.ToString();
         //disposed with fiber
         counter.SubscribeToKeyedBatch(fiber, keyResolver, 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: SubToKeyedBatch

        public void SubToKeyedBatch()
        {
            Channel<KeyValuePair<string, string>> channel = new Channel<KeyValuePair<string, string>>();
            StubCommandContext queue = new StubCommandContext();
            bool received = false;
            Action<IDictionary<string, KeyValuePair<string, string>>> onReceive =
                delegate(IDictionary<string, KeyValuePair<string, string>> data)
                    {
                        Assert.AreEqual(2, data.Keys.Count);
                        Assert.AreEqual(data["0"], new KeyValuePair<string, string>("0", "4"));
                        Assert.AreEqual(data["1"], new KeyValuePair<string, string>("1", "3"));
                        received = true;
                    };
            Converter<KeyValuePair<string, string>, string> key =
                delegate(KeyValuePair<string, string> pair) { return pair.Key; };
            channel.SubscribeToKeyedBatch(queue, key, onReceive, 0);

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

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


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