AsyncKeyedLock 2.0.2

AsyncKeyedLock AsyncKeyedLock

GitHub Workflow Status Nuget Nuget

An asynchronous .NET Standard 2.0 library that allows you to lock based on a key (keyed semaphores), only allowing a defined number of concurrent threads that share the same key.

For example, if you're processing transactions, you may want to limit to only one transaction per user so that the order is maintained, but meanwhile allowing parallel processing of multiple users.

Installation

The recommended means is to use NuGet, but you could also download the source code from here.

Usage

var asyncKeyedLocker = new AsyncKeyedLocker();
using (var lockObj = await asyncKeyedLocker.LockAsync(myObject))
{
	...
}

You can also set the maximum number of requests for the semaphore that can be granted concurrently (set to 1 by default):

var asyncKeyedLocker = new AsyncKeyedLocker(2);

If you would like to see how many concurrent requests there are for a semaphore for a given key:

int myCount = asyncKeyedLocker.GetCount(myObject);

And if for some reason you need to force release the requests in the semaphore for a key:

asyncKeyedLocker.ForceRelease(myObject);

You may also use Dependency Injection to inject an instance of AsyncKeyedLock.

Credits

This library is based on Stephen Cleary's solution.

Showing the top 20 packages that depend on AsyncKeyedLock.

Packages Downloads
Volo.Abp.DistributedLocking.Abstractions
Package Description
14
Volo.Abp.DistributedLocking.Abstractions
Package Description
13
Volo.Abp.DistributedLocking.Abstractions
Package Description
12
Volo.Abp.DistributedLocking.Abstractions
Package Description
11

Updated documentation.

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
7.0.2 4 10/18/2024
7.0.1 8 08/21/2024
7.0.0 4 07/24/2024
7.0.0-rc3 5 07/23/2024
7.0.0-rc2 4 07/23/2024
7.0.0-rc1 7 06/30/2024
7.0.0-beta 7 06/30/2024
7.0.0-alpha 6 06/30/2024
6.4.2 8 04/26/2024
6.4.1 7 05/01/2024
6.4.0 8 05/10/2024
6.3.4 16 02/01/2024
6.3.4-rc 8 01/31/2024
6.3.4-beta 8 02/01/2024
6.3.3 8 01/17/2024
6.3.2 10 01/17/2024
6.3.0 10 01/17/2024
6.2.6 11 01/13/2024
6.2.5 11 01/08/2024
6.2.5-alpha 13 01/03/2024
6.2.4 11 12/20/2023
6.2.3 12 12/15/2023
6.2.3-beta 12 12/19/2023
6.2.2 12 10/19/2023
6.2.1 24 06/02/2023
6.2.0 12 07/01/2023
6.1.1 10 07/02/2023
6.1.1-rc 14 10/18/2023
6.1.1-beta 11 06/20/2023
6.1.0 14 07/01/2023
6.0.5 12 07/02/2023
6.0.5-alpha 12 06/19/2023
6.0.4 12 06/19/2023
6.0.4-rc6 12 06/30/2023
6.0.4-rc5 15 06/20/2023
6.0.4-rc3 11 06/19/2023
6.0.4-rc 14 06/19/2023
6.0.4-beta 11 07/02/2023
6.0.4-alpha 14 07/02/2023
6.0.3 13 06/21/2023
6.0.2 13 07/02/2023
6.0.1 13 06/19/2023
5.1.2 10 06/20/2023
5.1.1 11 06/30/2023
5.1.0 11 07/19/2023
5.0.4 8 06/20/2023
5.0.3 15 07/14/2023
5.0.3-rc 12 06/30/2023
5.0.2-rc 13 06/21/2023
5.0.1 13 06/30/2023
4.0.2 15 07/01/2023
3.2.3 10 08/05/2023
3.2.1 11 06/20/2023
3.2.0 13 06/20/2023
3.0.1 12 06/19/2023
3.0.0 11 07/02/2023
2.0.3 12 06/19/2023
2.0.2 9 07/02/2023
2.0.1 10 06/19/2023
2.0.0 13 06/19/2023
1.1.0 13 06/19/2023
1.0.1 13 07/01/2023
1.0.0 13 06/20/2023