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