/// <summary>
 /// Acquires the lock synchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Usage:
 /// <code>
 ///     using (myLock.Acquire(...))
 ///     {
 ///         /* we have the lock! */
 ///     }
 ///     // dispose releases the lock
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></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</returns>
 public FileDistributedLockHandle Acquire(TimeSpan?timeout = null, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.Acquire(this, timeout, cancellationToken);
 ZooKeeperDistributedSemaphoreHandle IInternalDistributedSemaphore <ZooKeeperDistributedSemaphoreHandle> .Acquire(TimeSpan?timeout, CancellationToken cancellationToken) =>
 DistributedLockHelpers.Acquire(this, timeout, cancellationToken);
Example #3
0
 /// <summary>
 /// Acquires the lock synchronously, failing with <see cref="TimeoutException"/> if the wait times out
 /// <code>
 ///     using (myLock.Acquire(...))
 ///     {
 ///         // we have the lock
 ///     }
 ///     // dispose releases the lock
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on acquiring the lock. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></param>
 /// <param name="cancellationToken">Specifies a token by which the wait can be canceled</param>
 /// <returns>An <see cref="IDisposable"/> "handle" which can be used to release the lock</returns>
 public IDisposable Acquire(TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(DistributedLockHelpers.Acquire(this, timeout, cancellationToken));
 }
Example #4
0
 ZooKeeperDistributedReaderWriterLockHandle IInternalDistributedReaderWriterLock <ZooKeeperDistributedReaderWriterLockHandle> .AcquireWriteLock(TimeSpan?timeout, CancellationToken cancellationToken) =>
 DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: true);
 /// <summary>
 /// Acquires a READ lock synchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage:
 /// <code>
 ///     using (myLock.AcquireReadLock(...))
 ///     {
 ///         /* we have the lock! */
 ///     }
 ///     // dispose releases the lock
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></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</returns>
 public SqlDistributedReaderWriterLockHandle AcquireReadLock(TimeSpan?timeout = null, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: false);
 /// <summary>
 /// Acquires a WRITE lock synchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage:
 /// <code>
 ///     using (myLock.AcquireWriteLock(...))
 ///     {
 ///         /* we have the lock! */
 ///     }
 ///     // dispose releases the lock
 /// </code>
 /// </summary>
 /// <param name="timeout">How long to wait before giving up on the acquisition attempt. Defaults to <see cref="Timeout.InfiniteTimeSpan"/></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</returns>
 public PostgresDistributedReaderWriterLockHandle AcquireWriteLock(TimeSpan?timeout = null, CancellationToken cancellationToken = default) =>
 DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: true);