ReconArt.Synchronization.UnitDistributorSlim
2.0.0
Prefix Reserved
dotnet add package ReconArt.Synchronization.UnitDistributorSlim --version 2.0.0
NuGet\Install-Package ReconArt.Synchronization.UnitDistributorSlim -Version 2.0.0
<PackageReference Include="ReconArt.Synchronization.UnitDistributorSlim" Version="2.0.0" />
<PackageVersion Include="ReconArt.Synchronization.UnitDistributorSlim" Version="2.0.0" />
<PackageReference Include="ReconArt.Synchronization.UnitDistributorSlim" />
paket add ReconArt.Synchronization.UnitDistributorSlim --version 2.0.0
#r "nuget: ReconArt.Synchronization.UnitDistributorSlim, 2.0.0"
#:package ReconArt.Synchronization.UnitDistributorSlim@2.0.0
#addin nuget:?package=ReconArt.Synchronization.UnitDistributorSlim&version=2.0.0
#tool nuget:?package=ReconArt.Synchronization.UnitDistributorSlim&version=2.0.0
ReconArt.Synchronization.UnitDistributorSlim
Overview
ReconArt.Synchronization.UnitDistributorSlim is a .NET library that allows multi-threaded access to a shared resource with a limited supply by distributing that supply fairly. It supports priority-based distribution and is optimized for working with 6 priorities (from 0 to 5).
Features
- Fair distribution of limited resources
- Support for priority-based distribution
- Optimized for 6 priorities (0 to 5)
- Compatible with .NET 10 and .NET 11
Installation
To install the ReconArt.Synchronization.UnitDistributorSlim package, use the NuGet Package Manager or the Package Manager Console with the following command:
Install-Package ReconArt.Synchronization.UnitDistributorSlim
Usage
Creating a Unit Distributor
You can create a UnitDistributorSlim instance by specifying the total supply:
using ReconArt.Synchronization;
var unitDistributor = new UnitDistributorSlim(100); // 100 units available
Taking Units
You can attempt to take units asynchronously, with optional priority and timeout:
// Asynchronous take with priority
await unitDistributor.TryTakeAsync(10, 2); // 10 units with priority 2
// Asynchronous take with priority and timeout
bool success = await unitDistributor.TryTakeAsync(10, 2, TimeSpan.FromSeconds(10));
Returning Units
To return units to the distributor, call the Return method:
unitDistributor.Return(10); // Return 10 units
Handling Unit Overflow
If you attempt to return more units than the distributor's maximum supply, a UnitOverflowException will be thrown:
try
{
unitDistributor.Return(200); // Attempt to return 200 units
}
catch (UnitOverflowException ex)
{
Console.WriteLine(ex.Message);
}
Contributing
If you'd like to contribute to the project, please reach out to the ReconArt/synchronization-primitives team.
Support
If you encounter any issues or require assistance, please file an issue in the GitHub Issues section of the repository.
Authors and Acknowledgments
Developed by ReconArt, Inc..
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- ReconArt.PriorityQueue (>= 2.0.0)
-
net11.0
- ReconArt.PriorityQueue (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.