private static IEnumerator PreformThreadedOperation(Action threadedOperation) { var thread = new Thread(new ThreadStart(threadedOperation)); thread.Start(); yield return(TinyCoro.WaitUntil(() => !thread.IsAlive)); }
/// <summary> /// Adds an new TinyCoro to the pool after the currently exceutiny one (or last if none are running) /// </summary> /// <param name="threadedOperation"></param> /// <returns></returns> public static TinyCoro SpawnNext(Func<IEnumerator> operation) { var coro = new TinyCoro(operation); var index = _allCoros.Count; if (_currentCoro != null) index = _allCoros.IndexOf(_currentCoro) + 1; _allCoros.Insert(index, coro); return coro; }
/// <summary> /// Adds an new TinyCoro to the pool after the currently exceutiny one (or last if none are running) /// </summary> /// <param name="threadedOperation"></param> /// <returns></returns> public static TinyCoro SpawnNext(Func <IEnumerator> operation) { var coro = new TinyCoro(operation); var index = _allCoros.Count; if (_currentCoro != null) { index = _allCoros.IndexOf(_currentCoro) + 1; } _allCoros.Insert(index, coro); return(coro); }
public static TinyCoro SpawnAfter(Action threadedOperation) { return(TinyCoro.SpawnNext(() => PreformThreadedOperation(threadedOperation))); }
public static void StepAllCoros() { for (int i = 0; i < _allCoros.Count; ) { //Step normal _currentCoro = _allCoros[i]; if (_currentCoro.Alive) _currentCoro.Step(); if (!_currentCoro.Alive) { _allCoros.RemoveAt(i); } else { ++i; } } _currentCoro = null; }