/// <summary> /// Executes multiple subroutines at once, for as long as a condition is true /// </summary> public static CallInstruction ExecuteWhile(System.Func <bool> masterCondition, params IEnumerable <Instruction>[] slaveSubroutines) { // 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>(); foreach (var subroutineSource in slaveSubroutines) { subroutines.Add(new Coroutine(subroutineSource)); } var concurrentNode = new Concurrent(Utils.Any, subroutines); // Then pass that to a While node with the original condition return(new CallInstruction(new While(concurrentNode, 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))); }