mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-11-22 05:43:29 +01:00
parent
fa4d021368
commit
a3af44becb
3 changed files with 8 additions and 1 deletions
|
@ -11,7 +11,6 @@ namespace Coroutine {
|
||||||
|
|
||||||
internal ActiveCoroutine(IEnumerator<IWait> enumerator) {
|
internal ActiveCoroutine(IEnumerator<IWait> enumerator) {
|
||||||
this.enumerator = enumerator;
|
this.enumerator = enumerator;
|
||||||
this.enumerator.MoveNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Cancel() {
|
public bool Cancel() {
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace Coroutine {
|
||||||
private static readonly List<ActiveCoroutine> EventCoroutines = new List<ActiveCoroutine>();
|
private static readonly List<ActiveCoroutine> EventCoroutines = new List<ActiveCoroutine>();
|
||||||
|
|
||||||
public static ActiveCoroutine Start(IEnumerator<IWait> coroutine) {
|
public static ActiveCoroutine Start(IEnumerator<IWait> coroutine) {
|
||||||
|
if (!coroutine.MoveNext())
|
||||||
|
return null;
|
||||||
var inst = new ActiveCoroutine(coroutine);
|
var inst = new ActiveCoroutine(coroutine);
|
||||||
var type = inst.GetCurrentType();
|
var type = inst.GetCurrentType();
|
||||||
if (type == WaitType.Tick)
|
if (type == WaitType.Tick)
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Test {
|
||||||
var seconds = CoroutineHandler.Start(WaitSeconds());
|
var seconds = CoroutineHandler.Start(WaitSeconds());
|
||||||
CoroutineHandler.Start(PrintEvery10Seconds(seconds));
|
CoroutineHandler.Start(PrintEvery10Seconds(seconds));
|
||||||
|
|
||||||
|
CoroutineHandler.Start(EmptyCoroutine());
|
||||||
|
|
||||||
CoroutineHandler.InvokeLater(new WaitSeconds(10), () => {
|
CoroutineHandler.InvokeLater(new WaitSeconds(10), () => {
|
||||||
Console.WriteLine("Raising test event");
|
Console.WriteLine("Raising test event");
|
||||||
CoroutineHandler.RaiseEvent(TestEvent);
|
CoroutineHandler.RaiseEvent(TestEvent);
|
||||||
|
@ -53,5 +55,9 @@ namespace Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IEnumerator<IWait> EmptyCoroutine() {
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue