Soenneker.Asyncs.Semaphores 4.0.6

Prefix Reserved
dotnet add package Soenneker.Asyncs.Semaphores --version 4.0.6
                    
NuGet\Install-Package Soenneker.Asyncs.Semaphores -Version 4.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Asyncs.Semaphores" Version="4.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Asyncs.Semaphores" Version="4.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Asyncs.Semaphores" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Asyncs.Semaphores --version 4.0.6
                    
#r "nuget: Soenneker.Asyncs.Semaphores, 4.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Asyncs.Semaphores@4.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Asyncs.Semaphores&version=4.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Asyncs.Semaphores&version=4.0.6
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Asyncs.Semaphores

A low-allocation asynchronous semaphore for bounded in-process concurrency.

The single-waiter path uses a direct handoff slot. Heavier contention spills into a zero-allocation intrusive MPSC queue backed by pooled IValueTaskSource waiters. Permit count and pending handoff ownership share one atomic state, allowing competing releasers to batch queue consumption with less synchronization.

Installation

dotnet add package Soenneker.Asyncs.Semaphores

Usage

Create a semaphore with the desired concurrency limit, then dispose every acquired lease:

using Soenneker.Asyncs.Semaphores;

var semaphore = new AsyncSemaphore(4);

using SemaphoreLease lease = await semaphore.Acquire(cancellationToken);
await ProcessAsync(cancellationToken);

The single-argument constructor makes the initial and maximum permit counts equal. To begin with fewer permits available, specify both values:

var semaphore = new AsyncSemaphore(initialCount: 0, maxCount: 4);
semaphore.Release();

Release() and Release(int) can signal permits explicitly. Disposing a lease releases its owned permit automatically, so do not manually release that same permit.

Try without waiting

if (semaphore.TryAcquire(out SemaphoreLease lease))
{
    using (lease)
    {
        // One permit is owned here.
    }
}

Acquire returns a ValueTask<SemaphoreLease> and the lease is a value type, so an immediately available permit requires no allocation. Contended waiter nodes are pooled for reuse. SemaphoreLease.Dispose() is idempotent for the same lease variable; because it is a mutable struct, do not dispose copies of a lease.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Soenneker.Asyncs.Semaphores:

Package Downloads
Soenneker.Compression.SevenZip

A utility library for 7zip compression related operations

Soenneker.Playwrights.Crawler

A configurable Playwright crawler with rich stealth and control options.

Soenneker.Pdfs.Html

A utility library for generating PDF documents from HTML using Playwright.

Soenneker.Flywheel.Dashboard

A real-time Blazor dashboard for monitoring and managing Soenneker Flywheel.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.6 2,386 9/4/2026
4.0.5 261 9/3/2026