Class AsyncKeyLock<TKey>
Extension of the AsyncLock that enables fine-grained locking on a given key. Concurrent lock requests using different keys can execute simultaneously, while requests to lock using the same key will be forced to wait. This object is thread-safe and internally uses a pooling mechanism to minimize allocation of new locks.
Implements
Inherited Members
Namespace: SixLabors.ImageSharp.Web.Synchronization
Assembly: SixLabors.ImageSharp.Web.dll
Syntax
public class AsyncKeyLock<TKey> : IDisposable
Type Parameters
Name | Description |
---|---|
TKey | The type of the key. |
Constructors
| Improve this Doc View SourceAsyncKeyLock(Int32)
Initializes a new instance of the AsyncKeyLock<TKey> class.
Declaration
public AsyncKeyLock(int maxPoolSize = 64)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxPoolSize | The maximum number of locks that should be pooled for reuse. |
Methods
| Improve this Doc View SourceDispose()
Releases all resources used by the current instance of the AsyncKeyLock<TKey> class.
Declaration
public void Dispose()
LockAsync(TKey)
Locks the current thread asynchronously.
Declaration
public Task<IDisposable> LockAsync(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key identifying the specific object to lock against. |
Returns
Type | Description |
---|---|
Task<IDisposable> | The IDisposable that will release the lock. |