Table of Contents

Class AsyncKeyLock<TKey>

Namespace
SixLabors.ImageSharp.Web.Synchronization
Assembly
SixLabors.ImageSharp.Web.dll

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.

public sealed class AsyncKeyLock<TKey> : IDisposable where TKey : notnull

Type Parameters

TKey

The type of the key.

Inheritance
AsyncKeyLock<TKey>
Implements
Inherited Members

Constructors

AsyncKeyLock(int)

Initializes a new instance of the AsyncKeyLock<TKey> class.

public AsyncKeyLock(int maxPoolSize = 64)

Parameters

maxPoolSize int

The maximum number of locks that should be pooled for reuse.

Methods

Dispose()

Releases all resources used by the current instance of the AsyncKeyLock<TKey> class.

public void Dispose()

LockAsync(TKey)

Locks the current thread asynchronously.

public Task<IDisposable> LockAsync(TKey key)

Parameters

key TKey

The key identifying the specific object to lock against.

Returns

Task<IDisposable>

The IDisposable that will release the lock.