public TimelineEntry(ICFunc coroutineFunction) { Start = DateTime.Now; _children = new List <TimelineEntry>(); _coroutineFunction = coroutineFunction; SetFunctionName(); }
IEnumerator CoroutineWithInternalErrorHandling() { startMessage = "STARTED"; yield return(new WaitForSecondsRealtime(1)); //we can yield it with catch or wait on it and check errors //we will use an empty catch to completely swallow the error yield return(new CFunc(ThrowExceptionCoroutine()).Catch(e => { })); endMessage = "FINISHED"; yield return(new WaitForSecondsRealtime(1)); //Here we will use our own wait and check the error manually. then we don't need a catch block. //The reason it does not buble the error is because we don't yield the ICFunc startMessage = "STARTED ANOTHER"; ICFunc coroFunc2 = CoroutineUtility.Start(ThrowExceptionCoroutine()); while (!coroFunc2.IsDone) { yield return(null); } if (coroFunc2.Error != null) { Debug.Log("We should have already seen an error log, but here is another.."); } endMessage = "FINISHED ANOTHER"; }
void Example_Checking_IsDone() { SetNewTest("This test shows how you can use the IsDone property to check if a coroutine is complete"); CFunc coroutine = new CFunc(CoroutineWithError()); StartCoroutine(coroutine); _coroutineFunction = coroutine; }
public ITimelineEntry Add(ICFunc coroutineFunction, object owner = null) { TimelineEntry entry = new TimelineEntry(coroutineFunction); _entries.Add(entry); UpdateEntry(entry); return(entry); }
private void CreateSubRoutineForVal(object val) { _subroutine = _yieldInstructionFactory.CreateYieldInstructionWrapper(val); if (_subroutine != null && !_subroutine.HasUpdater) { _subroutine.RegisterUpdater(this); } }
public void Stop_removes_coroutine_from_indexer() { ICFunc cw = runnerUnderTest.Start(TestRoutine()); ICFunc cw2 = runnerUnderTest.Start(TestRoutine()); runnerUnderTest.Stop(cw); Assert.AreSame(cw2, runnerUnderTest[0]); }
public void SetUpTimelineEntryTests() { rootCoroutine = CreateRoutine(expectedFunctionName); entryUnderTest = timelineDataUnderTest.Add(rootCoroutine); // return true after registration with Add rootCoroutine.IsDone.Returns(true); rootCoroutine.LastUpdated.Returns(DateTime.Now); }
public CFunc(IEnumerator routine, IYieldInstructionFactory yieldInstructionFactory) { _yieldInstructionFactory = yieldInstructionFactory; _routine = routine; _subroutine = null; FunctionName = routine.ToString(); LastUpdated = DateTime.Now; OnCoroutineCreated(); }
void HandleSubRoutineDone() { Exception error = _subroutine.Error; _subroutine = null; if (error != null) { throw error; } }
public void Stop_decreases_count() { ICFunc cw = runnerUnderTest.Start(TestRoutine()); ICFunc cw2 = runnerUnderTest.Start(TestRoutine()); runnerUnderTest.Stop(cw); Assert.AreEqual(1, runnerUnderTest.Count); runnerUnderTest.Stop(cw2); Assert.AreEqual(0, runnerUnderTest.Count); }
public void SetUp() { CoroutineRunner cr = new CoroutineRunner(); runnerUnderTest = cr; moveNextCallCount = 0; mockTickGroup = ETickGroup.Update; mockCoroutine = new MockCoroutine(this); }
public void SetUp() { expectedCallCount = 10; runnerUnderTest = new CoroutineRunner(); moveNextCallCount = 0; mockTickGroup = ETickGroup.Update; mockCoroutine = Substitute.For <ICFunc>(); mockCoroutine.MoveNext().Returns(ci => ++ moveNextCallCount < expectedCallCount); mockCoroutine.TickGroup.Returns(ci => mockTickGroup); }
bool MoveNextWithTryCatch(ICFunc cFunc) { bool retVal = false; try { retVal = cFunc.MoveNext(); } catch (Exception e) { UnityEngine.Debug.LogException(e); } return(retVal); }
ICFunc AddFunction(ICFunc function) { if (_routines.Contains(function)) { throw new AlreadyAddedCoroutineException(); } function.RegisterUpdater(this); _routines.Add(function); return(function); }
public void RemovesCoroutineFromIndexer() { ICFunc cw = runnerUnderTest.Start(RoutineYieldNull()); ICFunc cw2 = runnerUnderTest.Start(RoutineYieldNull()); Assume.That(runnerUnderTest[0] == cw); Assume.That(runnerUnderTest[1] == cw2); runnerUnderTest.Stop(cw); Assert.AreSame(cw2, runnerUnderTest[0]); }
protected ICFunc CreateRoutine(string functionName, ICFunc parent = null) { ICFunc retVal = Substitute.For <ICFunc>(); retVal.FunctionName.Returns(functionName); if (parent != null) { retVal.HasUpdater.Returns(true); retVal.IsUpdatedBy(Arg.Is <object>(parent)).Returns(true); } return(retVal); }
void StepRoutines(ETickGroup tickGroup) { _removedDuringStepCount = 0; for (int i = _routines.Count - 1; i >= _removedDuringStepCount; i--) { ICFunc cw = _routines[i - _removedDuringStepCount]; if (cw.TickGroup == tickGroup) { if (MoveNextWithTryCatch(cw) == false) { RemoveFunction(cw); } } } }
public void ParentRelationshipIsUpdated() { ICFunc routineA = CreateRoutine("A"); ICFunc routineB = CreateRoutine("B"); ITimelineEntry a = timelineDataUnderTest.Add(routineA); ITimelineEntry b = timelineDataUnderTest.Add(routineB); routineB.IsUpdatedBy(Arg.Is <object>(routineA)).Returns(true); routineB.HasUpdater.Returns(true); Assume.That(b.Parent == null); timelineDataUnderTest.Update(); Assert.AreSame(a, b.Parent); }
public IEnumerator Stop_stops_coroutine() { ICFunc cw = null; cw = runnerUnderTest.Start(TestStopRoutine(() => { runnerUnderTest.Stop(cw); })); int i = 100; while (i-- > 0) { yield return(null); } Assert.IsTrue(goalReachedTestStopRoutine); Assert.IsFalse(goal2ReachedTestStopRoutine); }
void Update() { if (_coroutineFunction != null) { if (_coroutineFunction.IsDone) { if (_coroutineFunction.Error != null) { endMessage = "Coroutine Has Completed With Error"; } else { endMessage = "Coroutine Has Completed"; } _coroutineFunction = null; } } }
private ProcessResult ProcessSubRoutine() { if (_subroutine != null) { try { StepSubroutine(); if (!_subroutine.IsDone) { return(ProcessResult.NeedsMoreProcessing); } HandleSubRoutineDone(); } catch (Exception e) { _subroutine = null; throw e; } } return(ProcessResult.ProcessingComplete); }
private void OnGUI() { if (_coroutine == null) { EditorGUILayout.HelpBox("There is currently no coroutine running. Click the button to start a coroutine in the editor.", MessageType.None); if (GUILayout.Button("Start Coroutine")) { _coroutine = _runner.Start(MyCoroutine()); } } else { EditorGUILayout.HelpBox("The coroutine is currently running, you can check the logs for the output.", MessageType.Info); if (GUILayout.Button("Stop Coroutine")) { _runner.Stop(_coroutine); _coroutine = null; } } }
void DrawMenu() { Rect r = new Rect(10, 10, 200, 100); using (new GUILayout.AreaScope(r)) { GUI.enabled = !IsCoroutineRunning; if (GUILayout.Button("Start Using Example Singleton")) { _coroutine = ExampleSingleton.Inst.Start(ShowHelloWorldCoroutine()); } if (GUILayout.Button("Start Using Utility Singleton")) { _coroutine = CoroutineUtility.Start(ShowHelloWorldCoroutine()); } if (GUILayout.Button("Start Using Private Runner")) { _coroutineRunner.Start(ShowHelloWorldCoroutine()); } GUI.enabled = true; } }
public void WhenEntryIsAdded_IEnumeratorContainsExpectedParentChildRelationships( [Range(1, 4)] int expectedRootEntries, [Range(0, 3)] int expectedChildEntries, [Range(0, 2)] int expectedGrandChildEntries ) { Dictionary <ITimelineEntry, Dictionary <ITimelineEntry, List <ITimelineEntry> > > dict = new Dictionary <ITimelineEntry, Dictionary <ITimelineEntry, List <ITimelineEntry> > >(); for (int i = 0; i < expectedRootEntries; i++) { ICFunc parent = CreateRoutine("parent" + i); var rootEntry = timelineDataUnderTest.Add(parent); dict.Add(rootEntry, new Dictionary <ITimelineEntry, List <ITimelineEntry> >()); for (int j = 0; j < expectedChildEntries; j++) { ICFunc child = CreateRoutine("child" + j, parent); var childEntry = timelineDataUnderTest.Add(child); dict[rootEntry].Add(childEntry, new List <ITimelineEntry>()); for (int k = 0; k < expectedGrandChildEntries; k++) { ICFunc grandChild = CreateRoutine("grandChild", child); grandChild.HasUpdater.Returns(true); grandChild.IsUpdatedBy(Arg.Is <object>(child)).Returns(true); var grandChildEntry = timelineDataUnderTest.Add(grandChild); dict[rootEntry][childEntry].Add(grandChildEntry); } } } timelineDataUnderTest.Update(); Assert.AreEqual(expectedRootEntries, timelineDataUnderTest.Count()); int index = 0; foreach (var item in timelineDataUnderTest) { Assert.Contains(item, ((ICollection)dict.Keys)); Assert.IsNull(item.Parent); Assert.AreEqual(expectedChildEntries, item.Children.Count()); int childIndex = 0; foreach (var child in item.Children) { Assert.Contains(child, ((ICollection)dict[item].Keys)); Assert.AreSame(item, child.Parent); Assert.AreEqual(expectedGrandChildEntries, child.Children.Count()); int grandChildIndex = 0; foreach (var grandChild in child.Children) { Assert.Contains(grandChild, ((ICollection)dict[item][child])); Assert.AreSame(child, grandChild.Parent); Assert.AreEqual(0, grandChild.Children.Count()); grandChildIndex++; } childIndex++; } index++; } }
public IEnumerator AllKnownYieldTypesUsingRunner() { ICFunc cw = CoroutineUtility.Start(NewTestScriptWithEnumeratorPasses()); yield return(new WaitUntil(() => cw.IsDone)); }
void RemoveFunction(ICFunc function) { _routines.Remove(function); }
void CoroutineCreated(ICFunc coroutine) { _timelineData.Add(coroutine); }
public void Stop(ICFunc routine) { _removedDuringStepCount++; RemoveFunction(routine); }
public static void Stop(ICFunc coroutine) { Inst.Stop(coroutine); }
void HandleCoroutineCreated(ICFunc obj) { _timelineData.Add(obj); }