Tedd.AsyncLock 1.0.2

dotnet add package Tedd.AsyncLock --version 1.0.2
                    
NuGet\Install-Package Tedd.AsyncLock -Version 1.0.2
                    
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="Tedd.AsyncLock" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tedd.AsyncLock" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Tedd.AsyncLock" />
                    
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 Tedd.AsyncLock --version 1.0.2
                    
#r "nuget: Tedd.AsyncLock, 1.0.2"
                    
#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 Tedd.AsyncLock@1.0.2
                    
#: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=Tedd.AsyncLock&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Tedd.AsyncLock&version=1.0.2
                    
Install as a Cake Tool

Utilization Paradigms

Asynchronous Acquisition

using Tedd;

var mutex = new AsyncLock();

await using var guardian = await mutex.EnterAsync();
// Exclusive execution zone
await ExecuteAsynchronousOperation();
// Guardian disposal ensures lock release

Synchronous Acquisition

using Tedd;

var mutex = new AsyncLock();

using var guardian = mutex.Enter();
// Exclusive execution zone
ExecuteSynchronousOperation();
// Guardian disposal ensures lock release

Scoped Constructs

var mutex = new AsyncLock();

// Asynchronous scope
await using (var guardian = await mutex.EnterAsync())
{
    // Exclusive execution zone
    await ExecuteAsynchronousOperation();
}

// Synchronous scope
using (var guardian = mutex.Enter())
{
    // Exclusive execution zone
    ExecuteSynchronousOperation();
}

Cancellation Semantics

var mutex = new AsyncLock();
using var abortSource = new CancellationTokenSource();

try
{
    await using var guardian = await mutex.EnterAsync(abortSource.Token);
    await ExecuteOperation();
}
catch (OperationCanceledException)
{
    // Mitigate abortive state
}

Non-Blocking Probe

var mutex = new AsyncLock();

if (mutex.TryEnter(out var guardian))
{
    using (guardian)
    {
        // Immediate acquisition succeeded
        ExecuteOperation();
    }
}
else
{
    // Acquisition unattainable
    MitigateUnavailability();
}

Temporal Probe

var mutex = new AsyncLock();
var interval = TimeSpan.FromSeconds(5);

var guardian = await mutex.TryEnterAsync(interval);
if (guardian != null)
{
    await using (guardian)
    {
        // Acquisition within interval succeeded
        await ExecuteOperation();
    }
}
else
{
    // Interval elapsed without acquisition
    MitigateExpiration();
}

Interface Specification

AsyncLock Entity

Operations

Releaser Enter(CancellationToken cancellationToken = default)

Synchronously secures the mutex, suspending until attainable; propagates cancellation.

bool TryEnter(out Releaser? releaser)

Probes for immediate mutex availability sans suspension.

ValueTask<Releaser> EnterAsync(CancellationToken cancellationToken = default)

Asynchronously secures the mutex, awaiting availability; propagates cancellation.

ValueTask<Releaser?> TryEnterAsync(TimeSpan timeout, CancellationToken cancellationToken = default)

Asynchronously probes mutex within stipulated interval; returns null on expiration or cancellation.

Releaser Entity

Implements IDisposable and IAsyncDisposable for deterministic relinquishment. Employs atomic operations to preclude redundant releases. Align disposal modality with acquisition paradigm: synchronous via using, asynchronous via await using.

Concurrency Assurance

This construct guarantees thread-safety, enforcing singular possession at any juncture, thereby mitigating race conditions in multi-threaded contexts.

Efficacy Metrics

Leveraging SemaphoreSlim, it exhibits negligible overhead in low-contention scenarios, efficient queuing under load, and aversion to thread-pool depletion. Optimized for hybrid synchronous-asynchronous deployments.

Supported Runtimes

  • .NET Standard 2.1
Product 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 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2 95 8/8/2025
1.0.1 106 8/8/2025
1.0.0 105 8/8/2025

Pooling Release guardian object