Ejemplo n.º 1
0
        public IEnumerator CancelTaskRoutineShouldCancelTaskYetTest()
        {
            bool?cancellationExit = null;

            Routine.Task(token =>
            {
                var timeMeter = TimeMeter.New();
                while (timeMeter.ToSeconds() < 1)
                {
                    Thread.Sleep(15);
                    if (token.IsCancellationRequested)
                    {
                        cancellationExit = true;
                        return;
                    }
                }

                cancellationExit = false;
            }).Self(out var taskRoutine).InBackground();

            yield return(Routine.Delay(0.1f));

            taskRoutine.Cancel();

            // Отклик на отмену задачи ~15 мс ( Thread.Sleep(15) ), поэтому нужно немного подождать
            yield return(Routine.Delay(0.03f));

            Assert.NotNull(cancellationExit);
            Assert.True(cancellationExit);
        }
Ejemplo n.º 2
0
        public IEnumerator CancelDelayRoutineShouldBeCancelTest()
        {
            var timeMeter = TimeMeter.New();
            var routine   = Routine.Delay(1);

            routine.Cancel();
            yield return(routine);

            var elapsed = timeMeter.ToSeconds();

            Assert.Less(elapsed, 1f);
        }