Class AsyncLockAcquisition
Provides a set of methods to acquire different types of asynchronous lock.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public static class AsyncLockAcquisition
Methods
| Edit this page View SourceAcquireLockAsync<T>(T, CancellationToken)
Acquires exclusive lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
AcquireLockAsync<T>(T, TimeSpan)
Acquires exclusive lock associated with the given object.
Declaration
[Obsolete("Use AcquireLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
Acquires exclusive lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
TimeoutException | The lock cannot be acquired during the specified amount of time. |
AcquireReadLockAsync<T>(T, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
AcquireReadLockAsync<T>(T, TimeSpan)
Acquires reader lock associated with the given object.
Declaration
[Obsolete("Use AcquireReadLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync<T>(T, bool, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, bool upgrade, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
bool | upgrade | |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, bool upgrade, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
bool | upgrade | |
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync<T>(T, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync<T>(T, TimeSpan)
Acquires writer lock associated with the given object.
Declaration
[Obsolete("Use AcquireWriteLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | The object to be locked. |
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
Type | Description |
---|---|
ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to be locked. |
Exceptions
Type | Condition |
---|---|
TimeoutException | The lock cannot be acquired during the specified amount of time. |
OperationCanceledException | The operation has been canceled. |