< Summary

Class:GDX.Developer.WaitForMilliseconds
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/WaitForMilliseconds.cs
Covered lines:13
Uncovered lines:16
Coverable lines:29
Total lines:56
Line coverage:44.8% (13 of 29)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:5
Method coverage:40% (2 of 5)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WaitForMilliseconds(...)0%110100%
WaitAsync()0%12300%
Wait()0%6200%
While()0%440100%
Reset()0%2100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/WaitForMilliseconds.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System.Collections;
 6using System.Diagnostics;
 7using System.Threading.Tasks;
 8
 9namespace GDX.Developer
 10{
 11    public class WaitForMilliseconds
 12    {
 213        readonly Stopwatch m_Stopwatch = new Stopwatch();
 14        readonly int m_Duration;
 15
 216        public WaitForMilliseconds(int milliseconds)
 217        {
 218            m_Duration = milliseconds;
 219            m_Stopwatch.Restart();
 220        }
 21
 22        public async Task WaitAsync()
 023        {
 024            await Task.Run(() =>
 025            {
 26
 027                Task.Delay(m_Duration).Wait();
 028            });
 029        }
 30        public bool Wait()
 031        {
 032            if (m_Stopwatch.ElapsedMilliseconds >= m_Duration)
 033            {
 034                m_Stopwatch.Stop();
 035                return false;
 36            }
 37
 038            return true;
 039        }
 40
 41        public IEnumerator While()
 242        {
 54843            while (m_Stopwatch.ElapsedMilliseconds < m_Duration)
 54644            {
 54645                yield return null;
 54646            }
 47
 248            m_Stopwatch.Stop();
 249        }
 50
 51        public void Reset()
 052        {
 053            m_Stopwatch.Restart();
 054        }
 55    }
 56}