Codibre.ConcurrentTaskRunner
0.0.2
dotnet add package Codibre.ConcurrentTaskRunner --version 0.0.2
NuGet\Install-Package Codibre.ConcurrentTaskRunner -Version 0.0.2
<PackageReference Include="Codibre.ConcurrentTaskRunner" Version="0.0.2" />
paket add Codibre.ConcurrentTaskRunner --version 0.0.2
#r "nuget: Codibre.ConcurrentTaskRunner, 0.0.2"
// Install Codibre.ConcurrentTaskRunner as a Cake Addin #addin nuget:?package=Codibre.ConcurrentTaskRunner&version=0.0.2 // Install Codibre.ConcurrentTaskRunner as a Cake Tool #tool nuget:?package=Codibre.ConcurrentTaskRunner&version=0.0.2
Codibre.ConcurrentTaskRunner
A lib for concurrent, semaphore limited task runner under the hood
How to use?
Create an instance of options specifying the desired concurrency limit
ConcurrentTaskRunnerOptions options = new()
{
Limit = 3
};
Then, crate your runner instance
ConcurrentTaskRunner runner = new(options);
Finally, delegate the calls you want to limit concurrency
await runner.Run(MyCall);
Notice that, if the method Run never waits for MyCall to finish, it actually waits for a run slot to be freed, that is, if the concurrency limit hasn't been reached yet, it'll not wait and just pass through to MyCall execution in background.
Error handling
By default, any error the callback passed to Run throws is ignored, but you can treat it somehow informing a callback in the options to deal with it, like this:
ConcurrentTaskRunnerOptions options = new()
{
Limit = 3,
OnError = (Exception err) => Console.WriteLine(err.Message)
}
Errors thrown by OnError callback are not ignored, though, so write it carefully making sure it'll not throw anything so you don't get an untreated exception.
Procressing an Enumerable or AsyncEnumerable
It's also possible to use ConcurrentTaskRunner to process in a concurrently limited pace an enumerable or async enumerable instance. You just need to use our extension method RunConcurrently, like this:
await enumerable
.RunConcurrently(runner, (x) => MyCall(x));
Notice that a AsyncEnumerable may be infinite, so this is a blocking line in your code if that's the case. A CancellationToken instance can be used to create a stoppage condition:
await enumerable
.RunConcurrently(runner, (x) => MyCall(x), cancellationToken);
In this implementation, cancellationToken will not throw an error, but before executing the callback, it'll be checked to validate whether the cancellation had been requested or not, and it's not propagated to the callback. If you need it, though, you can propagate it yourself, like this:
await enumerable
.RunConcurrently(runner, (x) => MyCall(x, cancellationToken), cancellationToken);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Linq.Async (>= 6.0.1)
-
net7.0
- System.Linq.Async (>= 6.0.1)
-
net8.0
- System.Linq.Async (>= 6.0.1)
-
net9.0
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.