MagicAndre1981 / AsyncKeyedLock

An asynchronous .NET Standard 2.0 library that allows you to lock based on a key.

Home Page:https://www.nuget.org/packages/AsyncKeyedLock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AsyncKeyedLock AsyncKeyedLock

GitHub Workflow Status NuGet NuGet Codacy Grade

An asynchronous .NET Standard 2.0 library that allows you to lock based on a key (keyed semaphores), limiting concurrent threads sharing the same key to a specified number, with optional pooling for reducing memory allocations.

For example, suppose you were processing financial transactions, but while working on one account you wouldn't want to concurrently process a transaction for the same account. Of course, you could just add a normal lock, but then you can only process one transaction at a time. If you're processing a transaction for account A, you may want to also be processing a separate transaction for account B. That's where AsyncKeyedLock comes in: it allows you to lock but only if the key matches.

The library uses two very different methods for locking, one using an underlying ConcurrentDictionary that's cleaned up after use whilst the other using a technique called striped locking. Both have their advantages and disadvantages, and in order to help you choose you are highly recommended to read about it in the wiki.

Installation and usage

The documentation can be found in our wiki.

Credits

Check out our list of contributors!

About

An asynchronous .NET Standard 2.0 library that allows you to lock based on a key.

https://www.nuget.org/packages/AsyncKeyedLock

License:MIT License


Languages

Language:C# 100.0%