public IEnumerator CoroutineService_WaitForSecondsRealtimeAsync_WaitForSecondsRealtime()
        {
            var   coroutineService = new CoroutineService();
            float delaySeconds     = 0.05f;
            float startTimeSeconds = Time.realtimeSinceStartup;

            coroutineService.SetRealTime(startTimeSeconds);
            Task task = coroutineService.WaitForSecondsRealtimeAsync(delaySeconds);

            while (!task.IsCompleted)
            {
                coroutineService.SetRealTime(Time.realtimeSinceStartup);
                coroutineService.TickCoroutines();
                yield return(null);
            }

            Assert.IsTrue(Time.realtimeSinceStartup >= startTimeSeconds + delaySeconds, "Not enough time has passed");
        }
Example #2
0
        public void CoroutineService_WaitForSecondsRealtimeAsync_ReturnTaskThatCompletesAfterNumSeconds()
        {
            float     timeoutSeconds = 0.2f;
            Stopwatch sw             = new Stopwatch();

            var coroutineService = new CoroutineService();

            Task task = coroutineService.WaitForSecondsRealtimeAsync(0.1f);

            sw.Start();

            while (!task.IsCompleted && sw.ElapsedMilliseconds < timeoutSeconds)
            {
                coroutineService.SetRealTime(sw.ElapsedMilliseconds * 1000);
                Thread.Sleep(1);
            }

            Assert.Less(timeoutSeconds, sw.ElapsedMilliseconds, "Task timed out");
        }