<PackageReference Include="System.Threading.RateLimiting" Version="11.0.0-preview.6.26359.118" />

System.Threading.RateLimiting.RateLimiter

public abstract class RateLimiter : IAsyncDisposable, IDisposable
Represents a limiter type that users interact with to determine if an operation can proceed.
public abstract TimeSpan? IdleDuration { get; }

Specifies how long the RateLimiter has had all permits available. Used by RateLimiter managers that may want to clean up unused RateLimiters.

protected RateLimiter()

public static RateLimiter CreateChained(RateLimiter[] limiters)

Creates a single RateLimiter that wraps the passed in RateLimiters.

public ValueTask<RateLimitLease> AcquireAsync(int permitCount = 1, CancellationToken cancellationToken = default)

Wait until the requested permits are available or permits can no longer be acquired.

protected abstract ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, CancellationToken cancellationToken)

Method that RateLimiter implementations implement for AcquireAsync.

public RateLimitLease AttemptAcquire(int permitCount = 1)

Fast synchronous attempt to acquire permits.

protected abstract RateLimitLease AttemptAcquireCore(int permitCount)

Method that RateLimiter implementations implement for AttemptAcquire.

protected virtual void Dispose(bool disposing)

Dispose method for implementations to write.

public void Dispose()

Disposes the RateLimiter. This completes any queued acquires with a failed lease.

Disposes the RateLimiter asynchronously.

protected virtual ValueTask DisposeAsyncCore()

DisposeAsync method for implementations to write.

Gets a snapshot of the RateLimiter statistics if available.