コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: BasicExamples.cs プロジェクト: GWBasic/retlang
        public void ShouldIncreasePoolFiberSubscriberCountByOne()
        {
            var fiber = new PoolFiber();
            fiber.Start();
            var channel = new Channel<int>();

            Assert.AreEqual(0, fiber.SubscriptionsCount);
            Assert.AreEqual(0, channel.SubscribersCount);
            channel.Subscribe(fiber, x => { });

            Assert.AreEqual(1, fiber.SubscriptionsCount);
            Assert.AreEqual(1, channel.SubscribersCount);
            fiber.Dispose();

            Assert.AreEqual(0, fiber.SubscriptionsCount);
            Assert.AreEqual(0, channel.SubscribersCount);
        }