Closed BrennanConroy closed 2 years ago
Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.
Author: | BrennanConroy |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Threading`, `untriaged` |
Milestone: | - |
Looks good as proposed
namespace System.Threading.RateLimiting
{
public partial class RateLimiter : IAsyncDisposable, IDisposable
{
protected virtual void Dispose(bool disposing) { }
public void Dispose() { }
protected virtual ValueTask DisposeAsyncCore() { }
public ValueTask DisposeAsync() { }
}
}
Thanks 😃 Already done via https://github.com/dotnet/runtime/pull/61788
Background and motivation
https://github.com/dotnet/runtime/pull/61788 added the Rate Limiting work from https://github.com/dotnet/runtime/issues/52079 and while working on it we realized it made sense for rate limiters to be disposable. It started with the TokenBucket implementation which has a timer instance which should be disposed of. But it also made sense for the other rate limiters to release any pending acquisition requests from
limiter.WaitAsync(..., token);
as well as clean up any cancellation token registrations.Additionally, we expect some 3rd party implementations to be backed by a network resource and async disposal is preferred in those cases.
As well as implementing the two virtual methods on the rate limiter implementations (Concurrency, TokenBucket, FixedWindow, SlidingWindow)
We went ahead and made the API disposable, filing this to make sure we properly API review it.
API Proposal
API Usage
Alternative Designs
No response
Risks
No response