/// <summary> /// start a new coroutine, /// this coroutine will be executed immediately until the first yield return; /// if calling code yield return on the returned value, the calling code will be suspended until `work' is finished /// </summary> public WaitJob Start(Job work) { work.MoveNext(); m_toAddTasks.Add(work); WaitJob wjob = new WaitJob(work); _CheckJobReturn(work); return(wjob); }
/// <summary> /// check the coroutine return value, /// according to the returned value, current coroutine might be suspended temporarily /// </summary> private void _CheckJobReturn(Job task) { object ret = task.Current; Yielder yd = ret as Yielder; if (yd != null) { switch (yd.m_type) { case Yielder.TYPE.WAIT_JOB_DONE: { WaitJob wuc = (WaitJob)yd; m_waitExecs.Add(wuc.m_work, task); //current task will be suspended until given new task is finished //m_toAddTasks.Add(wuc.m_work); m_toDelTasks.Add(task); //current task is suspended } break; } } }