Ejemplo n.º 1
0
        public void AsyncRequestReplyWithPrivateChannelUsingThreads()
        {
            IFiber responder = new ThreadFiber();

            responder.Start();
            IFiber receiver = new ThreadFiber();

            receiver.Start();

            Channel <Channel <string> > requestChannel = new Channel <Channel <string> >();
            Channel <string>            replyChannel   = new Channel <string>();
            AutoResetEvent             reset           = new AutoResetEvent(false);
            Action <Channel <string> > onRequest       = delegate(Channel <string> reply) { reply.Publish("hello"); };

            requestChannel.Subscribe(responder, onRequest);
            Action <string> onMsg = delegate(string msg)
            {
                Assert.AreEqual("hello", msg);
                reset.Set();
            };

            replyChannel.Subscribe(receiver, onMsg);
            Assert.IsTrue(requestChannel.Publish(replyChannel));
            Assert.IsTrue(reset.WaitOne(10000, false));

            responder.Dispose();
            receiver.Dispose();
        }
Ejemplo n.º 2
0
        public void RunThread()
        {
            ThreadFiber threadFiber = new ThreadFiber(new CommandQueue());

            threadFiber.Start();
            threadFiber.Dispose();
            threadFiber.Join();
        }
            private void CalculateNext(IntPair receivedPair)
            {
                var next = receivedPair.First + receivedPair.Second;

                var pairToPublish = new IntPair(receivedPair.Second, next);

                _outboundChannel.Publish(pairToPublish);

                if (next > _limit)
                {
                    Console.WriteLine("Stopping " + _name);
                    _threadFiber.Dispose();

                    return;
                }
                Console.WriteLine(_name + " " + next);
            }
Ejemplo n.º 4
0
        public void ShouldIncreaseThreadFiberSubscriberCountByOne()
        {
            var fiber = new ThreadFiber();

            fiber.Start();
            var channel = new Channel <int>();

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

            Assert.AreEqual(1, fiber.NumSubscriptions);
            Assert.AreEqual(1, channel.NumSubscribers);
            fiber.Dispose();

            Assert.AreEqual(0, fiber.NumSubscriptions);
            Assert.AreEqual(0, channel.NumSubscribers);
        }