/// <summary> /// Executes two subroutines at once, completes when the Master condition is true /// Note, because of this, the master coroutine will be wrapped in a State node, that is, /// if it ever completes, it will be restarted. /// </summary> public static CallInstruction <T> ExecuteWhile <T>(IEnumerable <Instruction <T> > masterStateCoroutine, System.Func <T, bool> masterCondition, IEnumerable <Instruction> slaveSubroutine) { var masterCoroutineState = new StateCoroutine <T>(masterStateCoroutine); var slaveCoroutineNode = new Coroutine(slaveSubroutine); return(new CallInstruction <T>(new While <T>(masterCoroutineState, slaveCoroutineNode, masterCondition))); }
/// <summary> /// Executes multiple subroutines at once, with one master and multiple slaves. /// </summary> public static CallInstruction <T> ExecuteWhile <T>(IEnumerable <Instruction <T> > masterStateCoroutine, System.Func <T, bool> masterCondition, params IEnumerable <Instruction>[] slaveSubroutines) { var masterCoroutineState = new StateCoroutine <T>(masterStateCoroutine); // Create a concurrent node with all the passed in subroutines as children // And only consider the concurrent subroutine complete when all children are complete. var subroutines = new List <ICoroutine <bool> >(); foreach (var subroutineSource in slaveSubroutines) { subroutines.Add(new TrueWhileRunning(new Coroutine(subroutineSource))); } var concurrentNode = new Concurrent <bool>(Utils.Any, subroutines); return(new CallInstruction <T>(new While <T>(masterCoroutineState, concurrentNode, masterCondition))); }