private void RunInternal(CoroutineCallbackWrapper wrapper) { if (numActive < maxActive) { IEnumerator runner = CoroutineRunner(wrapper); coroutineStarter(runner); } else { queue.Enqueue(wrapper); } }
private IEnumerator CoroutineRunner(CoroutineCallbackWrapper wrapper) { numActive++; IEnumerator coroutine = wrapper.Coroutine; while (true) { object current; try { if (coroutine.MoveNext() == false) { break; } current = coroutine.Current; } catch (System.Exception ex) { if (OnCoroutineError != null) { OnCoroutineError(ex.Message); } wrapper.ExecCallback(false); numActive--; yield break; } yield return(current); } wrapper.ExecCallback(true); numActive--; if (queue.Count > 0) { CoroutineCallbackWrapper next = queue.Dequeue(); RunInternal(next); } }
public void Run(IEnumerator coroutine, Action <bool> callback = null) { CoroutineCallbackWrapper wrapper = new CoroutineCallbackWrapper(coroutine, callback); RunInternal(wrapper); }