public async Task RunCoroutine_YieldCustomWaitObjectWithNotify() { var scheduler = new InterleavedCoroutineScheduler(); var waitObject = new CustomWaitObjectWithNotifyCompletion(); var coroutine = new CustomWaitObjectCoroutine(waitObject); scheduler.Execute(coroutine); scheduler.Update(0); Assert.Equal(CoroutineStatus.Running, coroutine.Status); Task completionTask = Task.Run(async() => { await Task.Delay(500); waitObject.Complete(null); }); while (coroutine.Status == CoroutineStatus.Running) { scheduler.Update(0); await Task.Delay(10); } Assert.Equal(TaskStatus.RanToCompletion, completionTask.Status); Assert.Equal(CoroutineStatus.CompletedNormal, coroutine.Status); }
public void RunCoroutine_YieldCustomWaitObject() { var scheduler = new InterleavedCoroutineScheduler(); var waitObject = new CustomWaitObject(); var coroutine = new CustomWaitObjectCoroutine(waitObject); scheduler.Execute(coroutine); for (int i = 0; i < 10; i++) { scheduler.Update(0); } Assert.Equal(CoroutineStatus.Running, coroutine.Status); waitObject.Complete(null); scheduler.Update(0); Assert.Equal(CoroutineStatus.CompletedNormal, coroutine.Status); }
public void RunCoroutine_YieldCustomWaitObject_WithException() { var scheduler = new InterleavedCoroutineScheduler(); var waitObject = new CustomWaitObject(); var coroutine = new CustomWaitObjectCoroutine(waitObject); scheduler.Execute(coroutine); for (int i = 0; i < 10; i++) { scheduler.Update(0); } Assert.Equal(CoroutineStatus.Running, coroutine.Status); waitObject.Complete(new Exception()); scheduler.Update(0); Assert.Equal(CoroutineStatus.CompletedWithException, coroutine.Status); Assert.IsType <AggregateException>(coroutine.Exception); }