private async void AwaitTask(LitTask task) { try{ await task; }catch (System.Exception e) { _exception = e; }finally{ _waiting = false; } }
public IEnumerator ContinueWhenAll() { var startTime = System.DateTime.Now; var op = new ContinueLitTaskOperation(LitTask.WhenAll(new LitTask[] { Delay(100), Delay(1000), })); yield return(op); Assert.Greater(DateTime.Now, startTime + TimeSpan.FromMilliseconds(1000)); }
public IEnumerator ContinueWhenAny() { var startTime = System.DateTime.Now; var op = new ContinueLitTaskOperation <LitTask.WhenAnyResult>(LitTask.WhenAny(new LitTask[] { Delay(1000), Delay(100), })); yield return(op); Assert.GreaterOrEqual(System.DateTime.Now, startTime + System.TimeSpan.FromMilliseconds(100)); Assert.LessOrEqual(System.DateTime.Now, startTime + System.TimeSpan.FromMilliseconds(1000)); Assert.AreEqual(op.value.FirstCompletedTaskIndex, 1); }
public IEnumerator AwaitWhenAnyWithExceptionLater() { var startTime = System.DateTime.Now; var op = new AwaitLitTaskOperation <LitTask.WhenAnyResult>(LitTask.WhenAny(new LitTask[] { Delay(100), ThrowExceptionAfterAsync(1000), })); yield return(op); Assert.GreaterOrEqual(System.DateTime.Now, startTime + System.TimeSpan.FromMilliseconds(100)); Assert.LessOrEqual(System.DateTime.Now, startTime + System.TimeSpan.FromMilliseconds(1000)); Assert.AreEqual(op.value.FirstCompletedTaskIndex, 0); Assert.IsNull(op.value.Exception); }
public IEnumerator ContinueWhenAllWithException() { System.DateTime start = System.DateTime.Now; var op = new ContinueLitTaskOperation(LitTask.WhenAll(new LitTask[] { Delay(100), ThrowExceptionAfterAsync(10), })); yield return(op); Assert.NotNull(op.exception); Assert.True(op.exception is AggregateException); Assert.True((op.exception as AggregateException).InnerException is TestException); Assert.GreaterOrEqual(DateTime.Now, start + TimeSpan.FromMilliseconds(100)); }
public ContinueLitTaskOperation(LitTask task) { task.ContinueWith(OnContinue); }
public AwaitLitTaskOperation(LitTask task) { AwaitTask(task); }