private void RunTask(CoroutineTask context) { context.RunnerId = FindIdleRunner(); TasksRunning.Add(context); var runner = GetOrSpawnRunner(context.RunnerId); runner.CoStart(context); }
public void CoStart(CoroutineTask task) { if (IsRunning()) { throw new CoroutinePoolInvalidStateException("Coroutine is running, cannot start another task!"); } Reset(); _task = task; _state |= CoroutineState.Running; StartCoroutine(RunTask()); }
private void OnTaskFinished(CoroutineTask task) { if (!IdleSlots.Add(task.RunnerId)) { throw new CoroutineRunnerExistInIdleListException( string.Format("Runner(id: {0}) exist in idle list.", task.RunnerId)); } if (!TasksRunning.Remove(task)) { throw new CoroutinePoolException( string.Format("Task does not exist in running list, runnerId: {0}, handle: {1}", task.RunnerId, task.Handle)); } }
public int StartCoroutine(IEnumerator task) { var handle = GenerateTaskHandle(); var context = new CoroutineTask { Handle = handle, Task = task }; if (TasksRunning.Count < Capacity) { RunTask(context); } else { TasksWaiting.Add(context); } return(handle); }