Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Jan 16, 2024
2 parents c956839 + 05653da commit 3d888e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion AsyncKeyedLock.Tests/AsyncKeyedLock.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="ListShuffle" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ An asynchronous .NET Standard 2.0 library that allows you to lock based on a key

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](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki).
The library uses two very different methods for locking, `AsyncKeyedLocker` which uses an underlying `ConcurrentDictionary` that's cleaned up after use and `StripedAsyncKeyedLocker` which uses 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](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki).

A simple non-keyed lock is also available through `AsyncNonKeyedLocker`.
A simple non-keyed lock is also available through [`AsyncNonKeyedLocker`](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki/How-to-use-AsyncNonKeyedLocker).

## Installation and usage
Using this library is straightforward. Here's a simple example:
Using this library is straightforward. Here's a simple example for using `AsyncKeyedLocker`:
```csharp
private static readonly AsyncKeyedLocker<string> _asyncKeyedLocker = new(o =>
{
Expand All @@ -26,14 +26,10 @@ using (await _asyncKeyedLocker.LockAsync("test123"))
}
```

Please read the full documentation in our [wiki](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki) for help in using this libary.
For more help with `AsyncKeyedLocker` or for examples with `StripedAsyncKeyedLocker` or `AsyncNonKeyedLocker` (for simple, non-keyed locking), please [take a look at our wiki](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki).

## Benchmarks
This library has been extensively benchmarked against several other options and [our benchmarks](https://github.com/MarkCiliaVincenti/AsyncKeyedLockBenchmarks) run publicly and transparently on Github Actions.

When striped locking is an option, the `StripedAsyncKeyedLocker` consistently beats any other option in terms of both speed as well as memory allocations.

When the traditional dictionary-based method is used, `AsyncKeyedLocker` with pooling provides a great balance in terms of speed and memory allocations, which is an excellent, safe go-to solution.
This library has been extensively benchmarked against several other options and [our benchmarks](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/wiki/Benchmarks) run publicly and transparently on Github Actions.

## Credits
Check out our [list of contributors](https://github.com/MarkCiliaVincenti/AsyncKeyedLock/blob/master/CONTRIBUTORS.md)!

0 comments on commit 3d888e3

Please sign in to comment.