dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

[API Proposal]: System.Threading.RateLimiting.RateLimiter.AcquireAsync(CancellationToken cancellationToken); #101793

Open TonyValenti opened 6 months ago

TonyValenti commented 6 months ago

Background and motivation

Acquiring one permit from a rate limiter and using a cancelation token is a common scenario. This should be built in to the core

API Proposal

namespace System.Threading.RateLimiting;

public class RateLimiter
{
    public ValueTask<RateLimitLease> AcquireAsync(CancellationToken cancellationToken);
}

API Usage

using var Lease = await RateLimiter.AcquireAsync(Token);

Alternative Designs

This could be implemented as an extension method.

Risks

No response

dotnet-policy-service[bot] commented 6 months ago

Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.