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

            var waitAll = runner.Create(() =>
            {
                var coroutines = new AwaitableCoroutine <int> [4];
                for (var i = 0; i < 4; i++)
                {
                    coroutines[i] = AwaitableCoroutine.DelayCount(0).SelectTo(i);
                }
                return(AwaitableCoroutine.WaitAll <int>(coroutines));
            });

            Assert.False(waitAll.IsCompleted);

            runner.Update();

            Assert.True(waitAll.IsCompleted);

            var res = waitAll.Result;

            Assert.NotNull(res);

            for (var i = 0; i < 4; i++)
            {
                Assert.Equal(i, res[i]);
            }
        }
        public void WaitAll2Test()
        {
            var runner = new CoroutineRunner();

            var waitAll = runner.Create(() =>
                                        AwaitableCoroutine.WaitAll(
                                            AwaitableCoroutine.DelayCount(0),
                                            AwaitableCoroutine.DelayCount(0)
                                            )
                                        );

            Assert.False(waitAll.IsCompleted);

            // completes children
            runner.Update();

            Assert.True(waitAll.IsCompleted);
        }
        public void WaitAllOfDelay0Test()
        {
            var runner = new CoroutineRunner();

            var waitAll = runner.Create(() =>
                                        AwaitableCoroutine.WaitAll(new AwaitableCoroutineBase[] {
                AwaitableCoroutine.DelayCount(0),
                AwaitableCoroutine.DelayCount(0),
                AwaitableCoroutine.DelayCount(0),
                AwaitableCoroutine.DelayCount(0),
            })
                                        );

            Assert.False(waitAll.IsCompleted);

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

            var waitAll = runner.Create(() =>
                                        AwaitableCoroutine.WaitAll(new AwaitableCoroutineBase[] {
                AwaitableCoroutine.DelayCount(1),
                AwaitableCoroutine.DelayCount(2),
                AwaitableCoroutine.DelayCount(3),
                AwaitableCoroutine.DelayCount(4),
            })
                                        );

            Assert.False(waitAll.IsCompleted);

            for (var i = 0; i < 4; i++)
            {
                runner.Update();
            }
            runner.Update();
            Assert.True(waitAll.IsCompleted);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public void CancelWithCanceledException()
        {
            var runner = new CoroutineRunner();

            var delay = runner.Create(() => AwaitableCoroutine.DelayCount(5));

            var co = runner.Context <AwaitableCoroutine>(() => AwaitableCoroutine.WaitAll(delay, delay));

            Assert.False(delay.IsCompleted);
            Assert.False(delay.IsCanceled);

            Assert.False(co.IsCompleted);
            Assert.False(co.IsCanceled);

            runner.Update();

            Assert.False(delay.IsCompleted);
            Assert.False(delay.IsCanceled);

            Assert.False(co.IsCompleted);
            Assert.False(co.IsCanceled);

            delay.Cancel();

            Assert.False(delay.IsCompleted);
            Assert.True(delay.IsCanceled);

            Assert.False(co.IsCompleted);
            Assert.False(co.IsCanceled);

            runner.Update();

            Assert.False(co.IsCompleted);
            Assert.True(co.IsCanceled);
            Assert.True(co.Exception is ChildCanceledException <AwaitableCoroutineBase>);
        }