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


C# Channel.Publish方法代码示例

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


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

示例1: ShouldCompletelyClearPendingActionsBeforeExecutingNewActions

        public void ShouldCompletelyClearPendingActionsBeforeExecutingNewActions()
        {
            var msgs = new List<int>();

            var sut = new StubFiber { ExecutePendingImmediately = true };
            var channel = new Channel<int>();
            const int count = 4;

            channel.Subscribe(sut, delegate(int x)
                                         {
                                             if (x == count)
                                             {
                                                 return;
                                             }

                                             channel.Publish(x + 1);
                                             msgs.Add(x);
                                         });

            channel.Publish(0);

            Assert.AreEqual(count, msgs.Count);
            for (var i = 0; i < msgs.Count; i++)
            {
                Assert.AreEqual(i, msgs[i]);
            }
        }
开发者ID:rix0rrr,项目名称:SiouxTube,代码行数:27,代码来源:StubFiberTests.cs

示例2: TestTailWithExampleLog

        public void TestTailWithExampleLog()
        {
            File.Delete("test.log");

            var tailfiber = new PoolFiber();
            var reset = new AutoResetEvent(false);

            using (var tail = new Tail())
            {
                var tailchannel = new Channel<string>();
                tailchannel.Subscribe(tailfiber, str =>
                                                     {
                                                         tail.OutputRecievedEvent += OnOutputRecievedEvent;
                                                         tail.Start("test.log");
                                                     });

                tailfiber.Start();

                using (var testlog = new CreateTestLog("test.log"))
                {
                    tailchannel.Publish("");
                    testlog.StartWritingToTestLog(10);
                    testlog.Stop(); //don't really need to call this, but heh, what the...
                }

                tail.Stop();
                while(tail.State != TailState.Stopped){/*wait for tail to stop*/}
            }

            File.Delete("test.log");
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:31,代码来源:TailTestsWithExampleLog.cs

示例3: PointToPointPerfTestWithInt

 public void PointToPointPerfTestWithInt()
 {
     var executor = new BoundedQueue(new PerfExecutor()) { MaxDepth = 10000, MaxEnqueueWaitTimeInMs = 1000 };
     using (var fiber = new ThreadFiber(executor))
     {
         fiber.Start();
         var channel = new Channel<int>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         Action<int> onMsg = delegate(int count)
                                 {
                                     if (count == max)
                                     {
                                         reset.Set();
                                     }
                                 };
         channel.Subscribe(fiber, onMsg);
         using (new PerfTimer(max))
         {
             for (var i = 0; i <= max; i++)
             {
                 channel.Publish(i);
             }
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:27,代码来源:PerfTests.cs

示例4: 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));
            }
        }
开发者ID:GWBasic,项目名称:retlang,代码行数:27,代码来源:BasicExamples.cs

示例5: 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

示例6: Run

        private static void Run(long n, bool useSameThread)
        {
            AutoResetEvent done1 = new AutoResetEvent(false), done2 = new AutoResetEvent(false);

            IQueue q1 = new DefaultQueue(), q2 = new DefaultQueue();
            IFiber f1 = new ThreadFiber(q1), f2 = useSameThread ? f1 : new ThreadFiber(q2);
            IChannel<long> c1 = new Channel<long>(), c2 = new Channel<long>();

            c2.Subscribe(f2, (x) =>
                {
                    if (x < n)
                    {
                        c1.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done2.Set();
                    }
                }
            );

            c1.Subscribe(f1, (x) =>
                {
                    if (x < n)
                    {
                        c2.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done1.Set();
                    }
                }
            );

            f1.Start();
            if (!useSameThread) f2.Start();

            c1.Publish(0);
            EventWaitHandle.WaitAll(new[] { done1, done2 });

            f1.Dispose();
            f2.Dispose();
        }
开发者ID:patrickcooney,项目名称:code,代码行数:43,代码来源:Program.cs

示例7: PubSubWithDedicatedThread

        public void PubSubWithDedicatedThread()
        {
            using (var fiber = new ThreadFiber())
            {
                fiber.Start();
                var channel = new Channel<string>();

                var reset = new AutoResetEvent(false);
                channel.Subscribe(fiber, delegate { reset.Set(); });
                channel.Publish("hello");

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

示例8: TestFromRetlangSitePoolFiber

        public void TestFromRetlangSitePoolFiber()
        {
            //the test from retlang basic example
            using (var fiber = new PoolFiber())
            {
                fiber.Start();
                var channel = new Channel<string>();

                var reset = new AutoResetEvent(false);
                channel.Subscribe(fiber, delegate { reset.Set(); });
                channel.Publish("hello");

                Assert.IsTrue(reset.WaitOne(5000, false));

            }
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:16,代码来源:RetlangTest.cs

示例9: Main

        private static void Main(string[] args)
        {
            IChannel<string> toProcess = new Channel<string>();
            IChannel<string> completed = new Channel<string>();

            //first fiber will place something on channel for 2nd fiber to process
            using (IFiber fiber1 = PoolFiber.StartNew())
            //2nd fiber just writes to the completed channel
            using (IDisposable processor = new ChannelAgent<string>(toProcess, s => completed.Publish("Received " + s)))
            //A logger that watches the completed channel.  Could be optional
            using (IDisposable logger = new ChannelAgent<string>(completed, Console.WriteLine))
            {
                int count = 0;
                //Start sending a message after a second, every 2 seconds...
                fiber1.Schedule(() => toProcess.Publish("Test" + count++), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
                Console.ReadKey();
            }
        }
开发者ID:chrisa23,项目名称:Fibrous,代码行数:18,代码来源:Program.cs

示例10: DisposeShouldClearAllLists

        public void DisposeShouldClearAllLists()
        {
            var sut = new StubFiber();
            var channel = new Channel<int>();

            channel.Subscribe(sut, x => { });
            sut.Schedule(() => { }, 1000);
            channel.Publish(2);

            Assert.AreEqual(1, sut.Subscriptions.Count);
            Assert.AreEqual(1, sut.Scheduled.Count);
            Assert.AreEqual(1, sut.Pending.Count);

            sut.Dispose();

            Assert.AreEqual(0, sut.Subscriptions.Count);
            Assert.AreEqual(0, sut.Scheduled.Count);
            Assert.AreEqual(0, sut.Pending.Count);
        }
开发者ID:rix0rrr,项目名称:SiouxTube,代码行数:19,代码来源:StubFiberTests.cs

示例11: 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

示例12: 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));
     }
 }
开发者ID:JackWangCUMT,项目名称:Fibrous,代码行数:19,代码来源:FiberTester.cs

示例13: PointToPointPerfTestWithInt

 public void PointToPointPerfTestWithInt(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var channel = new Channel<int>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var counter = new CounterInt(reset, max);
         channel.Subscribe(fiber, counter.OnMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             for (int i = 0; i <= max; i++)
                 channel.Publish(i);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:chrisa23,项目名称:Fibrous,代码行数:19,代码来源:PerfTests.cs

示例14: BasicPubSubWithPoolQueue

        public void BasicPubSubWithPoolQueue()
        {
            IFiber queue = new PoolFiber();
            queue.Start();
            Channel<string> hello = new Channel<string>();
            Channel<string> hello2 = new Channel<string>();

            AutoResetEvent reset = new AutoResetEvent(false);
            Action<string> receiveHello = delegate(string str)
                                              {
                                                  Assert.AreEqual("hello", str);
                                                  reset.Set();
                                              };
            hello.Subscribe(queue, receiveHello);
            hello2.Subscribe(queue, receiveHello);
            Assert.IsTrue(hello.Publish("hello"));
            Assert.IsTrue(reset.WaitOne(10000, false));
            queue.Dispose();
        }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:19,代码来源:ChannelTests.cs

示例15: 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);
            }
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:20,代码来源:RetlangTest.cs


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