/// <summary>
 /// Attempts to acquire the lock synchronously. Usage:
 /// <code>
 ///     using (var handle = myLock.TryAcquire(...))
 ///     {
 ///         if (handle != null) { /* we have the lock! */ }
 ///     }
 ///     // dispose releases the lock if we took it
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
 /// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
 /// <returns>A <see cref="FileDistributedLockHandle"/> which can be used to release the lock or null on failure</returns>
 public FileDistributedLockHandle?TryAcquire(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken);
 ZooKeeperDistributedSemaphoreHandle?IInternalDistributedSemaphore <ZooKeeperDistributedSemaphoreHandle> .TryAcquire(TimeSpan timeout, CancellationToken cancellationToken) =>
 DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken);
 /// <summary>
 /// Attempts to acquire a READ lock synchronously. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
 /// <code>
 ///     using (var handle = myLock.TryAcquireReadLock(...))
 ///     {
 ///         if (handle != null) { /* we have the lock! */ }
 ///     }
 ///     // dispose releases the lock if we took it
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
 /// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
 /// <returns>A <see cref="SqlDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
 public SqlDistributedReaderWriterLockHandle?TryAcquireReadLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: false);
예제 #4
0
 ZooKeeperDistributedReaderWriterLockHandle?IInternalDistributedReaderWriterLock <ZooKeeperDistributedReaderWriterLockHandle> .TryAcquireWriteLock(TimeSpan timeout, CancellationToken cancellationToken) =>
 DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: true);
 /// <summary>
 /// Attempts to acquire a WRITE lock synchronously. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
 /// <code>
 ///     using (var handle = myLock.TryAcquireWriteLock(...))
 ///     {
 ///         if (handle != null) { /* we have the lock! */ }
 ///     }
 ///     // dispose releases the lock if we took it
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to 0</param>
 /// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
 /// <returns>A <see cref="PostgresDistributedReaderWriterLockHandle"/> which can be used to release the lock or null on failure</returns>
 public PostgresDistributedReaderWriterLockHandle?TryAcquireWriteLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: true);