DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="5.17.2" />

 LeaseConsumer

public abstract class LeaseConsumer : Disposable, IAsyncDisposable
Represents client side of a lease in a distributed environment.
protected struct AcquisitionResult

Represents a result of lease acquisition operation.

public double ClockDriftBound { get; set; }

Gets or sets wall clock desync degree in the cluster.

public Timeout& modreq(System.Runtime.InteropServices.InAttribute) Expiration { get; }

Gets lease expiration timeout.

public LeaseIdentity& modreq(System.Runtime.InteropServices.InAttribute) LeaseId { get; }

Gets the lease version.

public CancellationToken Token { get; }

Gets the token bounded to the lease lifetime.

protected LeaseConsumer(TimeProvider provider = null)

Initializes a new lease consumer.

public ValueTask AcquireAsync(TimeSpan pauseDuration, Random pauseRandomizer = null, CancellationToken token = default)

Acquires the lease.

public Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> worker, CancellationToken token = default)

Executes the specified long-running operation that is protected by the lease lifetime.

public ValueTask<bool> ReleaseAsync(CancellationToken token = default)

Releases a lease.

Performs a call to ReleaseAsync across the application boundaries.

public ValueTask<bool> TryAcquireAsync(CancellationToken token = default)

Tries to acquire the lease.

protected abstract ValueTask<AcquisitionResult?> TryAcquireCoreAsync(CancellationToken token = default)

Performs a call to TryAcquireAsync across the application boundaries.

public ValueTask<bool> TryRenewAsync(CancellationToken token = default)

Tries to renew a lease.

Performs a call to TryRenewAsync or TryAcquireOrRenewAsync across the application boundaries.