public async void First_Win_Sync() { var ttr = new TestTaskRunner(); var t = AsyncEnumerable.Amb( AsyncEnumerable.Range(1, 5) .DoOnNext(async v => { await ttr.CreateCompleteTask(500); }), AsyncEnumerable.Range(6, 5) .DoOnNext(async v => { await ttr.CreateCompleteTask(1000); }) ) .GetAsyncEnumerator() ; try { for (var i = 1; i <= 5; i++) { var t0 = t.MoveNextAsync(); await ttr.TaskQueued(i * 500); ttr.AdvanceTimeBy(500); await t0; Assert.Equal(i, t.Current); } Assert.False(await t.MoveNextAsync()); } finally { await t.DisposeAsync(); } }
public async void Second_Win_Empty() { await AsyncEnumerable.Amb( AsyncEnumerable.Interval(11, 5, TimeSpan.FromMilliseconds(100)), AsyncEnumerable.Empty <long>() ) .AssertResult(); }
public async void Second_Win_Error() { await AsyncEnumerable.Amb( AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(200)), AsyncEnumerable.Error <long>(new InvalidOperationException()) ) .AssertFailure(typeof(InvalidOperationException)); }
public async void Second_Win() { await AsyncEnumerable.Amb( AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(200)), AsyncEnumerable.Interval(11, 5, TimeSpan.FromMilliseconds(100)) ) .AssertResult(11L, 12L, 13L, 14L, 15L); }
public async void First_Win() { await AsyncEnumerable.Amb( AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(100)), AsyncEnumerable.Interval(11, 5, TimeSpan.FromMilliseconds(200)) ) .AssertResult(1L, 2L, 3L, 4L, 5L); }
public async void First_Win_Sync() { var ttr = new TestTaskRunner(); var t = AsyncEnumerable.Amb( AsyncEnumerable.Range(1, 5) .DoOnNext(async v => { await ttr.CreateCompleteTask(500); }), AsyncEnumerable.Range(6, 5) .DoOnNext(async v => { await ttr.CreateCompleteTask(1000); }) ) .GetAsyncEnumerator(default)
public async void Any_Win() { var disposed = 0; await AsyncEnumerable.Amb( AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(100)).DoOnDispose(() => Interlocked.Increment(ref disposed)), AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(100)).DoOnDispose(() => Interlocked.Add(ref disposed, 128)) ) .AssertResult(1L, 2L, 3L, 4L, 5L); Assert.Equal(129, disposed); }