public void WaitAnyTest()
        {
            var runner = new CoroutineRunner();

            var flag = false;

            var waitAny = runner.Create(() =>
                                        AwaitableCoroutine.WaitAny(new AwaitableCoroutineBase[] {
                AwaitableCoroutine.While(() => true),
                AwaitableCoroutine.While(() => true),
                AwaitableCoroutine.While(() => true),
                AwaitableCoroutine.While(() => !flag),
            })
                                        );

            Assert.False(waitAny.IsCompleted);

            runner.Update();
            Assert.False(waitAny.IsCompleted);

            flag = true;

            runner.Update();
            Assert.True(waitAny.IsCompleted);
        }
        public void WaitAnyWithValuesTest()
        {
            var runner = new CoroutineRunner();

            var flag = false;

            var waitAny = runner.Create(() =>
            {
                return(AwaitableCoroutine.WaitAny <int>(new AwaitableCoroutine <int>[] {
                    AwaitableCoroutine.While(() => true).SelectTo(0),
                    AwaitableCoroutine.While(() => !flag).SelectTo(1),
                    AwaitableCoroutine.While(() => true).SelectTo(2),
                    AwaitableCoroutine.While(() => !flag).SelectTo(3),
                }));
            });

            Assert.False(waitAny.IsCompleted);

            runner.Update();
            Assert.False(waitAny.IsCompleted);

            flag = true;

            runner.Update();

            Assert.True(waitAny.IsCompleted);

            var res = waitAny.Result;

            Assert.Equal(1, res);
        }
예제 #3
0
        public void RunWhileCoroutine()
        {
            var runner = new CoroutineRunner();

            var condition = false;

            var coroutine = runner.Create(() => AwaitableCoroutine.While(() => !condition));

            for (var i = 0; i < 3; i++)
            {
                runner.Update();
                Assert.False(coroutine.IsCompleted);
            }

            condition = true;
            runner.Update();
            Assert.True(coroutine.IsCompleted);
        }
예제 #4
0
        public void WithExceptionsTest()
        {
            var runner = new CoroutineRunner();

            var(co1, co2, co3) = runner.Context(() =>
                                                (CreateWithException(), AwaitableCoroutine.While(() => true), CreateWithException())
                                                );

            var waitAll = runner.Create(() => AwaitableCoroutine.WaitAll(co1, co2, co3));

            Assert.False(co1.IsCompleted);
            Assert.False(co2.IsCompleted);

            runner.Update();

            Assert.Throws <System.AggregateException>(runner.Update);

            runner.Update();
            Assert.True(co1.IsCanceled);
            Assert.False(co2.IsCanceled);
            Assert.True(co3.IsCanceled);
            Assert.True(waitAll.IsCanceled);
        }