Class MassiveRateLimitHandler
- Namespace
- MassiveDotNet.Http
- Assembly
- MassiveDotNet.dll
Paces outbound requests against a client-side allowance, so a caller stays inside their tier's limit rather than discovering it through HTTP 429.
public sealed class MassiveRateLimitHandler : DelegatingHandler, IDisposable
- Inheritance
-
MassiveRateLimitHandler
- Implements
- Inherited Members
Remarks
Permits refill continuously rather than all at once on a window boundary. A burst up to PermitsPerWindow goes out immediately and everything after it is paced, which keeps a small batch fast while never exceeding the configured rate over a sustained run.
This handler belongs innermost, below any retry: a retried attempt is a request the server counts too, so it must spend a permit like any other (D30).
Constructors
MassiveRateLimitHandler(MassiveRateLimitOptions)
Initializes a new instance of the MassiveRateLimitHandler class.
public MassiveRateLimitHandler(MassiveRateLimitOptions options)
Parameters
optionsMassiveRateLimitOptionsThe allowance to enforce.
Exceptions
- ArgumentNullException
optionsis null.- InvalidOperationException
optionsholds a value it cannot act on.
Properties
AvailablePermits
How many requests may be sent right now without waiting. Exposed so a caller can report their own headroom; it is a sample, and may be stale by the time it is read.
public int AvailablePermits { get; }
Property Value
Exceptions
- ObjectDisposedException
The handler has been disposed.
Methods
Dispose(bool)
Releases the unmanaged resources used by the DelegatingHandler, and optionally disposes of the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to releases only unmanaged resources.
Send(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server.
protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- HttpResponseMessage
An HTTP response message.
Exceptions
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
- NotSupportedException
Always. The SDK issues no synchronous requests.
SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
The
requestwas null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
- MassiveRateLimitExceededException
The configured queue is full, so the request was rejected without being sent.