示例#1
0
文件: TestMonad.cs 项目: rayark/mast
        public void ConcurrentMonadArrayErrorTest()
        {
            var mc = Monad.WhenAll(
                new BlockMonad <int>(r => TestTask5(3, 3, r)),
                new BlockMonad <int>(r => TestTask5(4, 5, r)),
                new BlockMonad <int>(r => TestTask5(2, 1, r)),
                new BlockMonad <int>(r => TestTask5(1, 3, r)),
                new BlockMonad <int>(r => TestTask6("error", 3, r))
                );

            _Wait(mc);
            Assert.IsNull(mc.Result);
            Assert.AreEqual(mc.Error.Message, "error");
        }
示例#2
0
文件: TestMonad.cs 项目: rayark/mast
        public void ConcurrentMonadArrayTest()
        {
            var mc = Monad.WhenAll(
                new BlockMonad <int>(r => TestTask5(3, 3, r)),
                new BlockMonad <int>(r => TestTask5(4, 5, r)),
                new BlockMonad <int>(r => TestTask5(2, 1, r)),
                new BlockMonad <int>(r => TestTask5(1, 3, r))
                );

            _Wait(mc);

            Assert.AreEqual(mc.Result[0], 3);
            Assert.AreEqual(mc.Result[1], 4);
            Assert.AreEqual(mc.Result[2], 2);
            Assert.AreEqual(mc.Result[3], 1);
            Assert.IsNull(mc.Error);
        }
示例#3
0
文件: TestMonad.cs 项目: rayark/mast
        public void PoolThreadedMonadTest()
        {
            int t = 0;

            var m1 = new PoolThreadedMonad <int>(() =>
            {
                System.Threading.Thread.Sleep(500);
                return(3 * t);
            });

            var m2 = new BlockMonad <int>(r =>
            {
                r.Accept(2);
                return(Coroutine.Sleep(0.1f));
            }).Then(res => t = res);

            var m3 = Monad.WhenAll(m1, m2);

            _Wait(m3);

            Assert.AreEqual(6, m3.Result.Item1);
        }