public async Task MultipleAsyncIndexOutOfOrder() { var FirstSource = ValueTaskCompletionSource.New <int>(); var SecondSource = ValueTaskCompletionSource.New <int>(); await using var Enumerator = new[] { FirstSource.Task, SecondSource.Task }.InterleaveIndex().GetAsyncEnumerator(); var Waiter = Enumerator.MoveNextAsync(); Assert.IsFalse(Waiter.IsCompleted); SecondSource.TrySetResult(108); Assert.IsTrue(await Waiter); Assert.IsTrue(Enumerator.Current.result.IsCompleted); Assert.AreEqual(SecondSource.Task.Result, Enumerator.Current.result.Result); Assert.AreEqual(1, Enumerator.Current.index); Waiter = Enumerator.MoveNextAsync(); Assert.IsFalse(Waiter.IsCompleted); FirstSource.TrySetResult(42); Assert.IsTrue(await Waiter); Assert.IsTrue(Enumerator.Current.result.IsCompleted); Assert.AreEqual(FirstSource.Task.Result, Enumerator.Current.result.Result); Assert.AreEqual(0, Enumerator.Current.index); Assert.IsFalse(await Enumerator.MoveNextAsync()); }
public async Task ExceptionAsync() { var FirstSource = ValueTaskCompletionSource.New <int>(); await using var Enumerator = new[] { FirstSource.Task }.Interleave().GetAsyncEnumerator(); var Waiter = Enumerator.MoveNextAsync(); Assert.IsFalse(Waiter.IsCompleted); FirstSource.TrySetException(new ApplicationException("Test")); Assert.IsTrue(await Waiter); try { await Enumerator.Current; Assert.Fail("Did not throw"); } catch (ApplicationException) { } Assert.IsFalse(await Enumerator.MoveNextAsync()); }
public async Task Complete() { using var TaskSource = ValueTaskCompletionSource.New(); var Task = TaskSource.Task; Assert.IsFalse(Task.IsCompleted); Assert.IsTrue(TaskSource.TrySetResult()); await Task; }
public async Task CompleteResult() { using var TaskSource = ValueTaskCompletionSource.New <int>(); var Task = TaskSource.Task; Assert.IsFalse(Task.IsCompleted); Assert.IsTrue(TaskSource.TrySetResult(123)); var Result = await Task; Assert.AreEqual(123, Result); }
public async Task SingleAsync() { var FirstSource = ValueTaskCompletionSource.New <int>(); await using var Enumerator = new[] { FirstSource.Task }.Interleave().GetAsyncEnumerator(); var Waiter = Enumerator.MoveNextAsync(); Assert.IsFalse(Waiter.IsCompleted); FirstSource.TrySetResult(42); Assert.IsTrue(await Waiter); Assert.IsTrue(Enumerator.Current.IsCompleted); Assert.AreEqual(FirstSource.Task.Result, Enumerator.Current.Result); Assert.IsFalse(await Enumerator.MoveNextAsync()); }
public async Task ExceptionResult() { using var TaskSource = ValueTaskCompletionSource.New <int>(); var Task = TaskSource.Task; Assert.IsFalse(Task.IsCompleted); Assert.IsTrue(TaskSource.TrySetException(new ApplicationException())); try { var Result = await Task; Assert.Fail("Should not reach here"); } catch (ApplicationException) { } }
public async Task CancelEnumerableWith() { var FirstSource = ValueTaskCompletionSource.New <int>(); var CancelSource = new CancellationTokenSource(); await using var Enumerator = new[] { FirstSource.Task }.Interleave().WithCancellation(CancelSource.Token).GetAsyncEnumerator(); var Waiter = Enumerator.MoveNextAsync(); CancelSource.Cancel(); try { await Waiter; Assert.Fail("Did not cancel"); } catch (OperationCanceledException) { } }