/// <summary> /// Acquires the lock asynchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Usage: /// <code> /// await using (await myLock.AcquireAsync(...)) /// { /// /* 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 ValueTask <FileDistributedLockHandle> AcquireAsync(TimeSpan?timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken);
/// <summary> /// Acquires the lock asynchronously, failing with <see cref="TimeoutException"/> if the wait times out /// <code> /// using (await myLock.AcquireAsync(...)) /// { /// // 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 Task <IDisposable> AcquireAsync(TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken)) { return(DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken)); }
/// <summary> /// Acquires a semaphore ticket synchronously, failing with <see cref="TimeoutException"/> if the wait times out. /// <code> /// using (await mySemaphore.AcquireAsync(...)) /// { /// // success! /// } /// // dispose releases the ticket /// </code> /// </summary> /// <param name="timeout">How long to wait before giving up on acquiring the ticket. 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 AwaitableDisposable <IDisposable> AcquireAsync(TimeSpan?timeout = null, CancellationToken cancellationToken = default) { return(new AwaitableDisposable <IDisposable>(DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken))); }
/// <summary> /// Acquires a READ lock asynchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage: /// <code> /// await using (await myLock.AcquireReadLockAsync(...)) /// { /// /* 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="ZooKeeperDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns> public ValueTask <ZooKeeperDistributedReaderWriterLockHandle> AcquireReadLockAsync(TimeSpan?timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: false);
/// <summary> /// Acquires a WRITE lock asynchronously, failing with <see cref="TimeoutException"/> if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage: /// <code> /// await using (await myLock.AcquireWriteLockAsync(...)) /// { /// /* 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>An <see cref="OracleDistributedReaderWriterLockHandle"/> which can be used to release the lock</returns> public ValueTask <OracleDistributedReaderWriterLockHandle> AcquireWriteLockAsync(TimeSpan?timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: true);