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


C# Channel.Recv方法代码示例

本文整理汇总了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");
     }
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:29,代码来源:SelectTests.cs

示例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());
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:7,代码来源:QueuedChannelTests.cs

示例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());
     }
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:17,代码来源:SelectTests.cs

示例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);
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:10,代码来源:QueuedChannelTests.cs

示例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());
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:6,代码来源:QueuedChannelTests.cs

示例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());
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:6,代码来源:QueuedChannelTests.cs

示例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());
             }
         }
     });
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:17,代码来源:QueuedChannelTests.cs

示例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);
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:9,代码来源:QueuedChannelTests.cs

示例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());
             }
         }
     });
 }
开发者ID:austincb1,项目名称:NetChan,代码行数:17,代码来源:ChannelTests.cs

示例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);
 }
开发者ID:austincb1,项目名称:NetChan,代码行数:9,代码来源:ChannelTests.cs

示例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);
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:17,代码来源:SelectTests.cs

示例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());
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:10,代码来源:SelectTests.cs


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