KeyedLocks 1.0.0

Sync and async locking based on a key

Install-Package KeyedLocks -Version 1.0.0
dotnet add package KeyedLocks --version 1.0.0
<PackageReference Include="KeyedLocks" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KeyedLocks --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KeyedLocks, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install KeyedLocks as a Cake Addin
#addin nuget:?package=KeyedLocks&version=1.0.0

// Install KeyedLocks as a Cake Tool
#tool nuget:?package=KeyedLocks&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

KeyedLocks

Sync and async locking based on a key

Usage

This library provides the KeyedLock<T> type, which can be used like this:

var locks = new KeyedLock<string>();
using (locks.Lock("key"))
{
    //Do the important thing
}

The using block ensures that the lock will be released after.

In async code, you can also wait to acquire the lock asynchronously:

var locks = new KeyedLock<string>();
using (await locks.LockAsync("key"))
{
    //Do the important thing
}

Testing

KeyedLock<T> is internally based on a Dictionary<T, SemaphoreSlim>.
Semaphores are created and destroyed as needed.

This code has been tested with Microsoft Coyote to try to eliminate concurrency bugs.

Changelog

1.0.0

Initial release

KeyedLocks

Sync and async locking based on a key

Usage

This library provides the KeyedLock<T> type, which can be used like this:

var locks = new KeyedLock<string>();
using (locks.Lock("key"))
{
    //Do the important thing
}

The using block ensures that the lock will be released after.

In async code, you can also wait to acquire the lock asynchronously:

var locks = new KeyedLock<string>();
using (await locks.LockAsync("key"))
{
    //Do the important thing
}

Testing

KeyedLock<T> is internally based on a Dictionary<T, SemaphoreSlim>.
Semaphores are created and destroyed as needed.

This code has been tested with Microsoft Coyote to try to eliminate concurrency bugs.

Changelog

1.0.0

Initial release

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 43 4/22/2021