public async Task PushToUnlimitedQueue() { var asyncEnum = AsyncEnum.Range(0, 10); var queue = new Queue <int>(); await asyncEnum.PushToQueue(queue).LastAsync(); Assert.Equal(10, queue.Count); }
public async Task PushToUnlimitedList() { var asyncEnum = AsyncEnum.Range(0, 10); var list = new List <int>(); await asyncEnum.PushToList(list).LastAsync(); Assert.Equal(10, list.Count); }
public async Task PushToLimitedList() { var asyncEnum = AsyncEnum.Range(0, 10); var list = new List <int>(); await asyncEnum.PushToList(list, 5).LastAsync(); Assert.Equal(5, list.Count); Assert.Equal(5, list.First()); Assert.Equal(9, list.Last()); }
public async IAsyncEnumerable <IAsyncEnumerable <int> > GetStreams() { for (int i = 0; i < NumberOfStreams; i++) { yield return(AsyncEnum.Range(0, NumberOfStreamItems)); await Task.Delay(1); } await Task.CompletedTask; }
public async Task Test2() { var stream = AsyncEnum.Range(0, 300000); var stream2 = AsyncEnum.Range(0, 300000); var streams = new[] { stream, stream2 }; var sw = Stopwatch.StartNew(); //stream = stream.If(i => i % 2 == 0, i => i.Select(o => o * 2)); //stream = stream.Select(i => i * 2).ToReplayQueue(); await foreach (var item in stream) { lock (this) { _otherQueue.OnNext(item); } //using (await _asyncLock.LockAsync()) { //await _queue.Next(item); } } await foreach (var item in stream2) { lock (this) { _otherQueue.OnNext(item); } //using (await _asyncLock.LockAsync()) { //await _queue.Next(item); } } //await _queue.Complete(); _otherQueue.OnCompleted(); //stream = AsyncEnumerableEx.Merge(streams); //stream = streams.MergeSequential(); var result = await _otherQueue.ToAsyncEnumerable().ToListAsync(); sw.Stop(); }