diff --git a/Coroutine/ActiveCoroutine.cs b/Coroutine/ActiveCoroutine.cs index 03a8812..cd69783 100644 --- a/Coroutine/ActiveCoroutine.cs +++ b/Coroutine/ActiveCoroutine.cs @@ -11,7 +11,6 @@ namespace Coroutine { internal ActiveCoroutine(IEnumerator enumerator) { this.enumerator = enumerator; - this.enumerator.MoveNext(); } public bool Cancel() { diff --git a/Coroutine/CoroutineHandler.cs b/Coroutine/CoroutineHandler.cs index 43ba3ca..6ca268e 100644 --- a/Coroutine/CoroutineHandler.cs +++ b/Coroutine/CoroutineHandler.cs @@ -9,6 +9,8 @@ namespace Coroutine { private static readonly List EventCoroutines = new List(); public static ActiveCoroutine Start(IEnumerator coroutine) { + if (!coroutine.MoveNext()) + return null; var inst = new ActiveCoroutine(coroutine); var type = inst.GetCurrentType(); if (type == WaitType.Tick) diff --git a/Test/Example.cs b/Test/Example.cs index 451f925..75b401c 100644 --- a/Test/Example.cs +++ b/Test/Example.cs @@ -12,6 +12,8 @@ namespace Test { var seconds = CoroutineHandler.Start(WaitSeconds()); CoroutineHandler.Start(PrintEvery10Seconds(seconds)); + CoroutineHandler.Start(EmptyCoroutine()); + CoroutineHandler.InvokeLater(new WaitSeconds(10), () => { Console.WriteLine("Raising test event"); CoroutineHandler.RaiseEvent(TestEvent); @@ -53,5 +55,9 @@ namespace Test { } } + private static IEnumerator EmptyCoroutine() { + yield break; + } + } } \ No newline at end of file