Ejemplo n.º 1
0
        public async Task ProxyWorks()
        {
            Test  t  = new Test();
            ITest tp = FiberProxy <ITest> .Create(t);

            tp.Init();
            tp.Add(1);
            tp.Subtract(2);
            await Task.Delay(100);

            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            int result = 0;

            tp.Event1 += x => result = x;

            t.Trigger();
            await Task.Delay(100);

            Assert.AreEqual(1, result);

            tp.Dispose();
            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            Assert.IsTrue(t.Disposed);
        }
Ejemplo n.º 2
0
        public async Task NoFiberErrorAsync()
        {
            Random rnd = new Random();

            using Fiber gen1 = new Fiber();
            using Fiber gen2 = new Fiber();
            using Fiber gen3 = new Fiber();

            using IStateManager stateMgr = FiberProxy <IStateManager> .Create(new StateManager ());

            gen1.Schedule(() => stateMgr.Add(letters[rnd.Next(16)].ToString()), TimeSpan.FromMilliseconds(10),
                          TimeSpan.FromMilliseconds(30));
            gen2.Schedule(() => stateMgr.Remove(letters[rnd.Next(16)].ToString()), TimeSpan.FromMilliseconds(10),
                          TimeSpan.FromMilliseconds(60));
            gen3.Schedule(() => stateMgr.Iterate(), TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(240));

            await Task.Delay(TimeSpan.FromSeconds(10));
        }