C# Class GSF.Threading.RateLimiter

A rate limiting system based on tokes.
Show file Open project: GridProtectionAlliance/gsf Class Usage Examples

Public Methods

Method Description
RateLimiter ( double tokensPerSecond = 10, int maxTokensQueue = 10 ) : System

Creates a RateLimiter

TryTakeToken ( ) : bool

Attempts to take a token from the rate limiter.

UpdateLimits ( double tokensPerSecond, int maxTokensQueue ) : void

Updates the limits associated with this rate limiter. Note, after this update, the tokens will be completely resupplied.

Method Details

RateLimiter() public method

Creates a RateLimiter
public RateLimiter ( double tokensPerSecond = 10, int maxTokensQueue = 10 ) : System
tokensPerSecond double The number of tokens per second that can be generated. Must be greater than zero and less than 1 billion
maxTokensQueue int The maximum number of tokens in the queue. Must be at least 1
return System

TryTakeToken() public method

Attempts to take a token from the rate limiter.
public TryTakeToken ( ) : bool
return bool

UpdateLimits() public method

Updates the limits associated with this rate limiter. Note, after this update, the tokens will be completely resupplied.
public UpdateLimits ( double tokensPerSecond, int maxTokensQueue ) : void
tokensPerSecond double The number of tokens per second that can be generated. Must be greater than zero and less than 1 billion
maxTokensQueue int The maximum number of tokens in the queue. Must be at least 1
return void