ReconArt.Synchronization.UnitDistributorSlim
1.0.0
Prefix Reserved
dotnet add package ReconArt.Synchronization.UnitDistributorSlim --version 1.0.0
NuGet\Install-Package ReconArt.Synchronization.UnitDistributorSlim -Version 1.0.0
<PackageReference Include="ReconArt.Synchronization.UnitDistributorSlim" Version="1.0.0" />
<PackageVersion Include="ReconArt.Synchronization.UnitDistributorSlim" Version="1.0.0" />
<PackageReference Include="ReconArt.Synchronization.UnitDistributorSlim" />
paket add ReconArt.Synchronization.UnitDistributorSlim --version 1.0.0
#r "nuget: ReconArt.Synchronization.UnitDistributorSlim, 1.0.0"
#:package ReconArt.Synchronization.UnitDistributorSlim@1.0.0
#addin nuget:?package=ReconArt.Synchronization.UnitDistributorSlim&version=1.0.0
#tool nuget:?package=ReconArt.Synchronization.UnitDistributorSlim&version=1.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 9 and .NET 8
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 | 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. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- ReconArt.PriorityQueue (>= 1.0.3)
-
net9.0
- ReconArt.PriorityQueue (>= 1.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 222 | 11/18/2024 |