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

System.Threading.RateLimiting.PartitionedRateLimiter<TResource>

public abstract class PartitionedRateLimiter<TResource> : IAsyncDisposable, IDisposable
Represents a limiter type that users interact with to determine if an operation can proceed given a specific TResource.

public ValueTask<RateLimitLease> AcquireAsync(TResource resource, 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(TResource resource, int permitCount, CancellationToken cancellationToken)

Method that PartitionedRateLimiter<T> implementations implement for AcquireAsync.

public RateLimitLease AttemptAcquire(TResource resource, int permitCount = 1)

Fast synchronous attempt to acquire permits.

protected abstract RateLimitLease AttemptAcquireCore(TResource resource, int permitCount)

Method that PartitionedRateLimiter<T> 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.

public abstract RateLimiterStatistics GetStatistics(TResource resource)

Gets a snapshot of the statistics for the resource if available.

public PartitionedRateLimiter<TOuter> WithTranslatedKey<TOuter>(Func<TOuter, TResource> keyAdapter, bool leaveOpen)

Translates PartitionedRateLimiter<TOuter> into the current PartitionedRateLimiter<T> using the keyAdapter to translate TOuter to TResource.