本文整理汇总了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));
}
}
示例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));
}
}
示例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);
}