public Task ConstructAndComplete() { var nagleBlock = new NagleBlock <ContentHash>(); nagleBlock.Complete(); return(nagleBlock.Completion); }
private async Task SendAndCompleteAsync( IList <ContentHash> items, NagleBlock <ContentHash> nagleBlock, ActionBlock <ContentHash[]> actionBlock) { nagleBlock.LinkTo(actionBlock); foreach (var item in items) { await nagleBlock.SendAsync(item); } nagleBlock.Complete(); await nagleBlock.Completion; actionBlock.Complete(); await actionBlock.Completion; }
public async Task PassItems(int itemCount) { var items = Enumerable.Range(0, itemCount).Select(i => ContentHash.Random()).ToList(); var results = new List <ContentHash>(); var testActionBlock = new ActionBlock <ContentHash[]>(contentHashes => { results.AddRange(contentHashes); }); var nagleBlock = new NagleBlock <ContentHash>(); await SendAndCompleteAsync(items, nagleBlock, testActionBlock); new HashSet <ContentHash>(items).SetEquals(results).Should().BeTrue(); }
public async Task ItemsPassedInBatches() { const int itemCount = 2; var results = new List <List <ContentHash> >(); var randomContentHashes = Enumerable.Range(0, itemCount).Select(i => ContentHash.Random()).ToList(); var testActionBlock = new ActionBlock <ContentHash[]>(contentHashes => { results.Add(contentHashes.ToList()); }); var nagleBlock = new NagleBlock <ContentHash>(1); await SendAndCompleteAsync(randomContentHashes, nagleBlock, testActionBlock); results.Count.Should().Be(2); var mergedResults = results.SelectMany(x => x).ToList(); mergedResults.Count.Should().Be(itemCount); new HashSet <ContentHash>(randomContentHashes).SetEquals(mergedResults).Should().BeTrue(); }