// Block synchronously until the given coroutine completes public static void SyncWait(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { } }
public static T SyncWaitGet <T>(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { } return((T)coroutine.ReturnValue); }
public void TestObjectTrace() { try { var runner = new CoRoutine( Runner() ); while ( runner.Pump() ) { } } catch ( Exception e ) { // Should print out a readable object trace Debug.LogException( e ); } }
// Block synchronously until the given coroutine completes // And give up after a timeout public static void SyncWaitWithTimeout(IEnumerator runner, float timeout) { var startTime = DateTime.UtcNow; var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { if ((DateTime.UtcNow - startTime).TotalSeconds > timeout) { throw new TimeoutException(); } } }
public void TestObjectTrace() { try { var runner = new CoRoutine(Runner()); while (runner.Pump()) { } } catch (Exception e) { // Should print out a readable object trace Debug.LogException(e); } }
// This can be used to make an untyped coroutine typed // (it's nice sometimes to work with untyped coroutines so you can yield other coroutines) public static IEnumerator <T> Wrap <T>(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { yield return(default(T)); } if (coroutine.ReturnValue != null) { if (!typeof(T).IsAssignableFrom(coroutine.ReturnValue.GetType())) { throw new CoRoutine.AssertException( string.Format("Unexpected type returned from coroutine! Expected '{0}' and found '{1}'", typeof(T).Name, coroutine.ReturnValue.GetType().Name)); } } yield return((T)coroutine.ReturnValue); }