A collection of extension methods for IAsyncEnumerable
$ dotnet add package Wolfgang.Extensions.IAsyncEnumerableHigh-performance, production-grade extension methods for IAsyncEnumerable<T> with comprehensive test coverage and strict code quality enforcement.
dotnet add package Wolfgang.Extensions.IAsyncEnumerable
NuGet Package: Coming soon to NuGet.org
using Wolfgang.Extensions.IAsyncEnumerable;
// Chunk an async stream into batches
await foreach (var chunk in asyncStream.ChunkAsync(maxChunkSize: 100, token: cancellationToken))
{
// Process each chunk (ICollection<T>)
await ProcessBatchAsync(chunk);
}
ChunkAsync<T>Splits an IAsyncEnumerable<T> into fixed-size chunks for batch processing.
public static async IAsyncEnumerable<ICollection<T>> ChunkAsync<T>(
this IAsyncEnumerable<T> source,
int maxChunkSize,
CancellationToken token = default)
Parameters:
source - The source async enumerable to chunkmaxChunkSize - Maximum size of each chunk (must be > 0)token - Optional cancellation tokenReturns: An async enumerable of collections, where each collection contains up to maxChunkSize elements.
Example:
var numbers = GetAsyncNumbers(); // IAsyncEnumerable<int>
await foreach (var batch in numbers.ChunkAsync(50))
{
Console.WriteLine($"Processing batch of {batch.Count} items");
// Last batch may be smaller than 50
}
This library supports multiple .NET versions:
net462)netstandard2.0)net8.0)net10.0)This project enforces strict code quality standards through 7 specialized analyzers and custom async-first rules:
This library uses BannedSymbols.txt to prohibit synchronous APIs and enforce async-first patterns:
Blocked APIs Include:
Task.Wait(), Task.Result - Use await insteadThread.Sleep() - Use await Task.Delay() insteadFile.ReadAllText) - Use async versionsReadAsync(), WriteAsync()Parallel.For/ForEach - Use Task.WhenAll() or Parallel.ForEachAsync()WebClient, BinaryFormatter)Why? To ensure all code is truly async and non-blocking for optimal performance in async contexts.
# Clone the repository
git clone https://github.com/Chris-Wolfgang/IAsyncEnumerable-Extensions.git
cd IAsyncEnumerable-Extensions
# Restore dependencies
dotnet restore
# Build the solution
dotnet build --configuration Release
# Run tests
dotnet test --configuration Release
# Run code formatting (PowerShell Core)
pwsh ./format.ps1
This project uses .editorconfig and dotnet format:
# Format code
dotnet format
# Verify formatting (as CI does)
dotnet format --verify-no-changes
See README-FORMATTING.md for detailed formatting guidelines.
Contributions are welcome! Please see CONTRIBUTING.md for:
This project is licensed under the MIT License. See the LICENSE file for details.
Built with: