using Medallion.Threading.Internal; namespace Medallion.Threading.Postgres; public partial class PostgresDistributedReaderWriterLock { // AUTO-GENERATED IDistributedSynchronizationHandle? IDistributedReaderWriterLock.TryAcquireReadLock(TimeSpan timeout, CancellationToken cancellationToken) => this.TryAcquireReadLock(timeout, cancellationToken); IDistributedSynchronizationHandle IDistributedReaderWriterLock.AcquireReadLock(TimeSpan? timeout, CancellationToken cancellationToken) => this.AcquireReadLock(timeout, cancellationToken); ValueTask IDistributedReaderWriterLock.TryAcquireReadLockAsync(TimeSpan timeout, CancellationToken cancellationToken) => this.TryAcquireReadLockAsync(timeout, cancellationToken).Convert(To.ValueTask); ValueTask IDistributedReaderWriterLock.AcquireReadLockAsync(TimeSpan? timeout, CancellationToken cancellationToken) => this.AcquireReadLockAsync(timeout, cancellationToken).Convert(To.ValueTask); IDistributedSynchronizationHandle? IDistributedReaderWriterLock.TryAcquireWriteLock(TimeSpan timeout, CancellationToken cancellationToken) => this.TryAcquireWriteLock(timeout, cancellationToken); IDistributedSynchronizationHandle IDistributedReaderWriterLock.AcquireWriteLock(TimeSpan? timeout, CancellationToken cancellationToken) => this.AcquireWriteLock(timeout, cancellationToken); ValueTask IDistributedReaderWriterLock.TryAcquireWriteLockAsync(TimeSpan timeout, CancellationToken cancellationToken) => this.TryAcquireWriteLockAsync(timeout, cancellationToken).Convert(To.ValueTask); ValueTask IDistributedReaderWriterLock.AcquireWriteLockAsync(TimeSpan? timeout, CancellationToken cancellationToken) => this.AcquireWriteLockAsync(timeout, cancellationToken).Convert(To.ValueTask); /// /// Attempts to acquire a READ lock synchronously. Multiple readers are allowed. Not compatible with a WRITE lock. Usage: /// /// using (var handle = myLock.TryAcquireReadLock(...)) /// { /// if (handle != null) { /* we have the lock! */ } /// } /// // dispose releases the lock if we took it /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to 0 /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock or null on failure public PostgresDistributedReaderWriterLockHandle? TryAcquireReadLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) => DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: false); /// /// Acquires a READ lock synchronously, failing with if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage: /// /// using (myLock.AcquireReadLock(...)) /// { /// /* we have the lock! */ /// } /// // dispose releases the lock /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock public PostgresDistributedReaderWriterLockHandle AcquireReadLock(TimeSpan? timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: false); /// /// Attempts to acquire a READ lock asynchronously. Multiple readers are allowed. Not compatible with a WRITE lock. Usage: /// /// await using (var handle = await myLock.TryAcquireReadLockAsync(...)) /// { /// if (handle != null) { /* we have the lock! */ } /// } /// // dispose releases the lock if we took it /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to 0 /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock or null on failure public ValueTask TryAcquireReadLockAsync(TimeSpan timeout = default, CancellationToken cancellationToken = default) => this.As>().InternalTryAcquireAsync(timeout, cancellationToken, isWrite: false); /// /// Acquires a READ lock asynchronously, failing with if the attempt times out. Multiple readers are allowed. Not compatible with a WRITE lock. Usage: /// /// await using (await myLock.AcquireReadLockAsync(...)) /// { /// /* we have the lock! */ /// } /// // dispose releases the lock /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock public ValueTask AcquireReadLockAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: false); /// /// Attempts to acquire a WRITE lock synchronously. Not compatible with another WRITE lock or an UPGRADE lock. Usage: /// /// using (var handle = myLock.TryAcquireWriteLock(...)) /// { /// if (handle != null) { /* we have the lock! */ } /// } /// // dispose releases the lock if we took it /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to 0 /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock or null on failure public PostgresDistributedReaderWriterLockHandle? TryAcquireWriteLock(TimeSpan timeout = default, CancellationToken cancellationToken = default) => DistributedLockHelpers.TryAcquire(this, timeout, cancellationToken, isWrite: true); /// /// Acquires a WRITE lock synchronously, failing with if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage: /// /// using (myLock.AcquireWriteLock(...)) /// { /// /* we have the lock! */ /// } /// // dispose releases the lock /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock public PostgresDistributedReaderWriterLockHandle AcquireWriteLock(TimeSpan? timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.Acquire(this, timeout, cancellationToken, isWrite: true); /// /// Attempts to acquire a WRITE lock asynchronously. Not compatible with another WRITE lock or an UPGRADE lock. Usage: /// /// await using (var handle = await myLock.TryAcquireWriteLockAsync(...)) /// { /// if (handle != null) { /* we have the lock! */ } /// } /// // dispose releases the lock if we took it /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to 0 /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock or null on failure public ValueTask TryAcquireWriteLockAsync(TimeSpan timeout = default, CancellationToken cancellationToken = default) => this.As>().InternalTryAcquireAsync(timeout, cancellationToken, isWrite: true); /// /// Acquires a WRITE lock asynchronously, failing with if the attempt times out. Not compatible with another WRITE lock or an UPGRADE lock. Usage: /// /// await using (await myLock.AcquireWriteLockAsync(...)) /// { /// /* we have the lock! */ /// } /// // dispose releases the lock /// /// /// How long to wait before giving up on the acquisition attempt. Defaults to /// Specifies a token by which the wait can be canceled /// A which can be used to release the lock public ValueTask AcquireWriteLockAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) => DistributedLockHelpers.AcquireAsync(this, timeout, cancellationToken, isWrite: true); }