![]() |
VOOZH | about |
dotnet add package EnumerableAsyncProcessor --version 3.8.4
NuGet\Install-Package EnumerableAsyncProcessor -Version 3.8.4
<PackageReference Include="EnumerableAsyncProcessor" Version="3.8.4" />
<PackageVersion Include="EnumerableAsyncProcessor" Version="3.8.4" />Directory.Packages.props
<PackageReference Include="EnumerableAsyncProcessor" />Project file
paket add EnumerableAsyncProcessor --version 3.8.4
#r "nuget: EnumerableAsyncProcessor, 3.8.4"
#:package EnumerableAsyncProcessor@3.8.4
#addin nuget:?package=EnumerableAsyncProcessor&version=3.8.4Install as a Cake Addin
#tool nuget:?package=EnumerableAsyncProcessor&version=3.8.4Install as a Cake Tool
Process Multiple Asynchronous Tasks in Various Ways - One at a time / Batched / Rate limited / Concurrently
👁 nuget
👁 Codacy Badge
👁 CodeFactor
Install via Nuget
Install-Package EnumerableAsyncProcessor
Because I've come across situations where you need to fine tune the rate at which you do things. Maybe you want it fast. Maybe you want it slow. Maybe you want it at a safe balance. Maybe you just don't want to write all the boilerplate code that comes with managing asynchronous operations!
Types
| Type | Source Object | Return Object | Method 1 | Method 2 |
|---|---|---|---|---|
RateLimitedParallelAsyncProcessor |
❌ | ❌ | .WithExecutionCount(int) |
.ForEachAsync(delegate) |
RateLimitedParallelAsyncProcessor<TInput> |
✔ | ❌ | .WithItems(IEnumerable<TInput>) |
.ForEachAsync(delegate) |
ResultRateLimitedParallelAsyncProcessor<TOutput> |
❌ | ✔ | .WithExecutionCount(int) |
.SelectAsync(delegate) |
ResultRateLimitedParallelAsyncProcessor<TInput, TOutput> |
✔ | ✔ | .WithItems(IEnumerable<TInput>) |
.SelectAsync(delegate) |
How it works
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set. As one finishes, another will start.
E.g. If you set a limit of 100, only 100 should ever run at any one time
This is a hybrid between Parallel Processor and Batch Processor (see below) - Trying to address the caveats of both. Increasing the speed of batching, but not overwhelming the system by using full parallelisation.
Usage
var ids = Enumerable.Range(0, 5000).ToList();
// SelectAsync for if you want to return something
var results = await ids
.SelectAsync(id => DoSomethingAndReturnSomethingAsync(id), CancellationToken.None)
.ProcessInParallel(levelOfParallelism: 100);
// ForEachAsync for when you have nothing to return
await ids
.ForEachAsync(id => DoSomethingAsync(id), CancellationToken.None)
.ProcessInParallel(levelOfParallelism: 100);
Types
| Type | Source Object | Return Object | Method 1 | Method 2 |
|---|---|---|---|---|
TimedRateLimitedParallelAsyncProcessor |
❌ | ❌ | .WithExecutionCount(int) |
.ForEachAsync(delegate) |
TimedRateLimitedParallelAsyncProcessor<TInput> |
✔ | ❌ | .WithItems(IEnumerable<TInput>) |
.ForEachAsync(delegate) |
ResultTimedRateLimitedParallelAsyncProcessor<TOutput> |
❌ | ✔ | .WithExecutionCount(int) |
.SelectAsync(delegate) |
ResultTimedRateLimitedParallelAsyncProcessor<TInput, TOutput> |
✔ | ✔ | .WithItems(IEnumerable<TInput>) |
.SelectAsync(delegate) |
How it works
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set over the timespan that you set. As one finishes, another will start, unless you've hit the maximum allowed for the current timespan duration.
E.g. If you set a limit of 100, and a timespan of 1 second, only 100 operation should ever run at any one time over the course of a second. If the operation finishes sooner than a second (or your provided timespan), it'll wait and then start the next operation once that timespan has elapsed.
This is useful in scenarios where, for example, you have an API but it has a request per second limit
Usage
var ids = Enumerable.Range(0, 5000).ToList();
// SelectAsync for if you want to return something
var results = await ids
.SelectAsync(id => DoSomethingAndReturnSomethingAsync(id), CancellationToken.None)
.ProcessInParallel(levelOfParallelism: 100, TimeSpan.FromSeconds(1));
// ForEachAsync for when you have nothing to return
await ids
.ForEachAsync(id => DoSomethingAsync(id), CancellationToken.None)
.ProcessInParallel(levelOfParallelism: 100, TimeSpan.FromSeconds(1));
Caveats
Types
| Type | Source Object | Return Object | Method 1 | Method 2 |
|---|---|---|---|---|
OneAtATimeAsyncProcessor |
❌ | ❌ | .WithExecutionCount(int) |
.ForEachAsync(delegate) |
OneAtATimeAsyncProcessor<TInput> |
✔ | ❌ | .WithItems(IEnumerable<TInput>) |
.ForEachAsync(delegate) |
ResultOneAtATimeAsyncProcessor<TOutput> |
❌ | ✔ | .WithExecutionCount(int) |
.SelectAsync(delegate) |
ResultOneAtATimeAsyncProcessor<TInput, TOutput> |
✔ | ✔ | .WithItems(IEnumerable<TInput>) |
.SelectAsync(delegate) |
How it works
Processes your Asynchronous Tasks One at a Time. Only one will ever progress at a time. As one finishes, another will start
Usage
var ids = Enumerable.Range(0, 5000).ToList();
// SelectAsync for if you want to return something
var results = await ids
.SelectAsync(id => DoSomethingAndReturnSomethingAsync(id), CancellationToken.None)
.ProcessOneAtATime();
// ForEachAsync for when you have nothing to return
await ids
.ForEachAsync(id => DoSomethingAsync(id), CancellationToken.None)
.ProcessOneAtATime();
Caveats
Types
| Type | Source Object | Return Object | Method 1 | Method 2 |
|---|---|---|---|---|
BatchAsyncProcessor |
❌ | ❌ | .WithExecutionCount(int) |
.ForEachAsync(delegate) |
BatchAsyncProcessor<TInput> |
✔ | ❌ | .WithItems(IEnumerable<TInput>) |
.ForEachAsync(delegate) |
ResultBatchAsyncProcessor<TOutput> |
❌ | ✔ | .WithExecutionCount(int) |
.SelectAsync(delegate) |
ResultBatchAsyncProcessor<TInput, TOutput> |
✔ | ✔ | .WithItems(IEnumerable<TInput>) |
.SelectAsync(delegate) |
How it works
Processes your Asynchronous Tasks in Batches. The next batch will not start until every Task in previous batch has finished
Usage
var ids = Enumerable.Range(0, 5000).ToList();
// SelectAsync for if you want to return something
var results = await ids
.SelectAsync(id => DoSomethingAndReturnSomethingAsync(id), CancellationToken.None)
.ProcessInBatches(batchSize: 100);
// ForEachAsync for when you have nothing to return
await ids
.ForEachAsync(id => DoSomethingAsync(id), CancellationToken.None)
.ProcessInBatches(batchSize: 100);
Caveats
Types
| Type | Source Object | Return Object | Method 1 | Method 2 |
|---|---|---|---|---|
ParallelAsyncProcessor |
❌ | ❌ | .WithExecutionCount(int) |
.ForEachAsync(delegate) |
ParallelAsyncProcessor<TInput> |
✔ | ❌ | .WithItems(IEnumerable<TInput>) |
.ForEachAsync(delegate) |
ResultParallelAsyncProcessor<TOutput> |
❌ | ✔ | .WithExecutionCount(int) |
.SelectAsync(delegate) |
ResultParallelAsyncProcessor<TInput, TOutput> |
✔ | ✔ | .WithItems(IEnumerable<TInput>) |
.SelectAsync(delegate) |
How it works
Processes your Asynchronous Tasks as fast as it can. All at the same time if it can
Usage
var ids = Enumerable.Range(0, 5000).ToList();
// SelectAsync for if you want to return something
var results = await ids
.SelectAsync(id => DoSomethingAndReturnSomethingAsync(id), CancellationToken.None)
.ProcessInParallel();
// ForEachAsync for when you have nothing to return
await ids
.ForEachAsync(id => DoSomethingAsync(id), CancellationToken.None)
.ProcessInParallel();
Caveats
As above, you can see that you can just await on the processor to get the results.
Below shows examples of using the processor object and the various methods available.
This is for when you need to Enumerate through some objects and use them in your operations. E.g. Sending notifications to certain ids
var httpClient = new HttpClient();
var ids = Enumerable.Range(0, 5000).ToList();
// This is for when you need to Enumerate through some objects and use them in your operations
var itemProcessor = Enumerable.Range(0, 5000).ToAsyncProcessorBuilder()
.SelectAsync(NotifyAsync)
.ProcessInParallel(100);
// Or
// var itemProcessor = AsyncProcessorBuilder.WithItems(ids)
// .SelectAsync(NotifyAsync, CancellationToken.None)
// .ProcessInParallel(100);
// GetEnumerableTasks() returns IEnumerable<Task<TOutput>> - These may have completed, or may still be waiting to finish.
var tasks = itemProcessor.GetEnumerableTasks();
// Or call GetResultsAsyncEnumerable() to get an IAsyncEnumerable<TOutput> so you can process them in real-time as they finish.
await foreach (var httpResponseMessage in itemProcessor.GetResultsAsyncEnumerable())
{
// Do something
}
// Or call GetResultsAsync() to get a Task<TOutput[]> that contains all of the finished results
var results = await itemProcessor.GetResultsAsync();
// My dummy method
Task<HttpResponseMessage> NotifyAsync(int id)
{
return httpClient.GetAsync($"https://localhost:8080/notify/{id}");
}
This is for when you need to don't need any objects - But just want to do something a certain amount of times. E.g. Pinging a site to warm up multiple instances
var httpClient = new HttpClient();
var itemProcessor = AsyncProcessorBuilder.WithExecutionCount(100)
.SelectAsync(PingAsync, CancellationToken.None)
.ProcessInParallel(10);
// GetEnumerableTasks() returns IEnumerable<Task<TOutput>> - These may have completed, or may still be waiting to finish.
var tasks = itemProcessor.GetEnumerableTasks();
// Or call GetResultsAsyncEnumerable() to get an IAsyncEnumerable<TOutput> so you can process them in real-time as they finish.
await foreach (var httpResponseMessage in itemProcessor.GetResultsAsyncEnumerable())
{
// Do something
}
// Or call GetResultsAsync() to get a Task<TOutput[]> that contains all of the finished results
var results = await itemProcessor.GetResultsAsync();
// My dummy method
Task<HttpResponseMessage> PingAsync()
{
return httpClient.GetAsync("https://localhost:8080/ping");
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 4 NuGet packages that depend on EnumerableAsyncProcessor:
| Package | Downloads |
|---|---|
|
TUnit.Engine
A .NET Testing Framework |
|
|
ModularPipelines
Write your pipelines in C#! |
|
|
TomLonghurst.PullRequestScanner
Package Description |
|
|
DotnetModularPipelines
Write your pipelines in C#! |
Showing the top 2 popular GitHub repositories that depend on EnumerableAsyncProcessor:
| Repository | Stars |
|---|---|
|
thomhurst/TUnit
A modern, fast and flexible .NET testing framework
|
|
|
thomhurst/ModularPipelines
Write your pipelines in C# !
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.8.4 | 2,075,574 | 8/11/2025 |
| 3.8.3 | 277 | 8/11/2025 |
| 3.8.2 | 316 | 8/11/2025 |
| 3.8.0 | 271 | 8/11/2025 |
| 3.6.3 | 12,218 | 8/10/2025 |
| 3.6.2 | 268 | 8/10/2025 |
| 3.6.0 | 281 | 8/10/2025 |
| 3.5.0 | 290 | 8/10/2025 |
| 3.3.3 | 492 | 8/9/2025 |
| 3.3.2 | 1,163 | 8/8/2025 |
| 3.2.0 | 1,348 | 8/8/2025 |
| 3.1.0 | 350 | 8/8/2025 |
| 3.0.2 | 9,554 | 8/7/2025 |
| 3.0.1 | 987 | 8/7/2025 |
| 3.0.0 | 360 | 8/7/2025 |
| 2.1.111 | 4,508 | 8/6/2025 |
| 2.1.0 | 456,662 | 1/25/2025 |
| 2.0.6 | 62,928 | 1/1/2025 |
| 2.0.0 | 471 | 12/30/2024 |
| 1.4.0 | 47,892 | 11/30/2024 |