using System.Collections.Generic; namespace NBC { public class RunnerProcess : IProcess { /// /// 当前运行的任务 /// protected readonly List Coroutines; /// /// 当前操作的信息 /// protected readonly FlushingOperation FlushingOperation; /// /// 准备要运行的任务 /// protected readonly Queue ReadyTask; /// /// 进程名称 /// protected string Name; public RunnerProcess(string name, List coroutines, Queue readyTask, FlushingOperation op) { Name = name; Coroutines = coroutines; ReadyTask = readyTask; FlushingOperation = op; } public NTaskStatus Process() { var flag = false; if (FlushingOperation.Kill) { flag = true; } else { for (var index = 0; index < ReadyTask.Count; index++) { // var task = ReadyTask[0]; var task = ReadyTask.Dequeue(); Coroutines.Add(task); // ReadyTask.RemoveAt(0); } if (Coroutines.Count == 0 || FlushingOperation.Paused) { flag = false; } else { var index = 0; var mustExit = false; do { var childTask = Coroutines[index]; var st = childTask.Process(); if (st >= NTaskStatus.Success) Coroutines.RemoveAt(index); //.splice(index, 1); else index++; mustExit = Coroutines.Count == 0 || index >= Coroutines.Count; } while (!mustExit); } } return flag ? NTaskStatus.Success : NTaskStatus.Running; } } }