本文整理汇总了C#中Channel.Recv方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.Recv方法的具体用法?C# Channel.Recv怎么用?C# Channel.Recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Channel
的用法示例。
在下文中一共展示了Channel.Recv方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_read_after_select_on_queued_Channels
public void can_read_after_select_on_queued_Channels()
{
var ch1 = new Channel<int>(1);
var ch2 = new Channel<bool>(1);
ThreadPool.QueueUserWorkItem(state => {
ch1.Send(123);
ch2.Send(true);
ch2.Close();
ch1.Send(124);
ch1.Close();
});
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.Select();
Debug.Print("got.Index = " + got.Index);
if (got.Index == 0) {
Assert.AreEqual(123, got.Value, "got.Value");
Assert.AreEqual(Maybe<bool>.Some(true), ch2.Recv());
}
else {
Assert.AreEqual(1, got.Index, "got.Index");
Assert.AreEqual(true, got.Value, "got.Value");
Assert.AreEqual(Maybe<int>.Some(123), ch1.Recv());
}
select.ClearAt(1);
got = select.Select();
Assert.AreEqual(0, got.Index, "got.Index, value =" + got.Value);
Assert.AreEqual(124, got.Value, "got.Value");
}
}
示例2: can_recv_one_item_before_closing
public void can_recv_one_item_before_closing()
{
var ch = new Channel<int>(1);
ThreadPool.QueueUserWorkItem(state => { ch.Send(123); ch.Close(); });
Assert.AreEqual(Maybe<int>.Some(123), ch.Recv());
Assert.AreEqual(Maybe<int>.None(), ch.TryRecv());
}
示例3: can_read_after_select
public void can_read_after_select()
{
var ch1 = new Channel<int>();
var ch2 = new Channel<bool>();
ThreadPool.QueueUserWorkItem(state => {
ch1.Send(123);
ch2.Send(true);
ch1.Send(124);
});
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.Select();
Assert.AreEqual(0, got.Index, "select.Index");
Assert.AreEqual(123, got.Value, "select.Value");
Assert.AreEqual(Maybe<bool>.Some(true), ch2.Recv());
Assert.AreEqual(Maybe<int>.Some(124), ch1.Recv());
}
}
示例4: send_blocks_when_capacity_reached_until_recv
public void send_blocks_when_capacity_reached_until_recv()
{
var ch = new Channel<bool>(1);
var start = Environment.TickCount;
ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(50); ch.Recv(); Thread.Sleep(100); ch.Recv(); });
ch.Send(true);
ch.Send(true);
var elapsed = Environment.TickCount - start;
Assert.IsTrue(elapsed >= 40 && elapsed < 100, "Elapsed " + elapsed);
}
示例5: recv_get_value_sent_by_thread_pool_thread
public void recv_get_value_sent_by_thread_pool_thread()
{
var ch = new Channel<int>(1);
ThreadPool.QueueUserWorkItem(state => ch.Send(123));
Assert.AreEqual(Maybe<int>.Some(123), ch.Recv());
}
示例6: recv_does_not_block_on_a_closed_Channel
public void recv_does_not_block_on_a_closed_Channel()
{
var ch = new Channel<int>(1);
ch.Close();
Assert.AreEqual(Maybe<int>.None(), ch.Recv());
}
示例7: z10_benchmark_send_and_receive
public void z10_benchmark_send_and_receive()
{
Benchmark.Go("queue size 10", (int runs) => {
var data = new Channel<int>(100);
ThreadPool.QueueUserWorkItem((state) => {
for (int i = 0; i < runs; i++) {
data.Send(i);
}
});
for (int i = 0; i < runs; i++) {
var got = data.Recv();
if (got.IsNone || got.Value != i) {
Assert.AreEqual(Maybe<int>.Some(i), data.Recv());
}
}
});
}
示例8: send_does_not_block_when_capacity_spare
public void send_does_not_block_when_capacity_spare()
{
var ch = new Channel<bool>(1);
var start = Environment.TickCount;
ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(50); ch.Recv(); });
ch.Send(true);
var elapsed = Environment.TickCount - start;
Assert.IsTrue(elapsed < 50, "Elapsed " + elapsed);
}
示例9: z_benchmark_send_and_recieve
public void z_benchmark_send_and_recieve()
{
Benchmark.Go("unbuffered", (int runs) => {
var data = new Channel<int>();
new Thread(() => {
for (int i = 0; i < runs; i++) {
data.Send(i);
}
}).Start();
for (int i = 0; i < runs; i++) {
var got = data.Recv();
if (got.IsNone || got.Value != i) {
Assert.AreEqual(Maybe<int>.Some(i), data.Recv());
}
}
});
}
示例10: send_blocks_until_recv
public void send_blocks_until_recv()
{
var ch = new Channel<bool>();
var start = Environment.TickCount;
ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(123); ch.Recv(); });
ch.Send(true);
var elasped = Environment.TickCount - start;
Assert.IsTrue(elasped > 100, "Elasped " + elasped);
}
示例11: select_can_send_on_unbuffered_channel
public void select_can_send_on_unbuffered_channel()
{
var ch1 = new Channel<int>();
var done = new AutoResetEvent(false);
Maybe<int> recvd = Maybe<int>.None();
ThreadPool.QueueUserWorkItem(state => {
recvd = ch1.Recv();
done.Set();
});
using (var chans = new Channels(Op.Send(ch1))) {
chans[0].Value = 123;
var got = chans.Select();
Assert.AreEqual(0, got.Index, "select.Index");
}
done.WaitOne();
Assert.AreEqual(Maybe<int>.Some(123), recvd);
}
示例12: select_can_send_on_buffered_channel
public void select_can_send_on_buffered_channel()
{
var ch1 = new Channel<int>(1);
using (var chans = new Channels(Op.Send(ch1))) {
chans[0].Value = 123;
var got = chans.Select();
Assert.AreEqual(0, got.Index, "select.Index");
}
Assert.AreEqual(Maybe<int>.Some(123), ch1.Recv());
}