PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.RateLimiter Class Reference

More...

Inheritance diagram for PeanutButter.Utils.RateLimiter:
PeanutButter.Utils.IRateLimiter

Public Member Functions

 RateLimiter (int maxCallsPerMinute)
 Constructs the rate limiter with the provided maxCallsPerMinute.
 RateLimiter (int maxCallsPerPeriod, TimeSpan period)
 Configures the rate limiter with the provided max calls per provided period.
void Run (Action action)
 Runs the synchronous code, rate-limited.
  • calls which come in within the sliding minute are performed until the configured rate per minute is reached, and extra calls are discarded
Parameters
action

async Task RunAsync (Func< Task > action)
 Runs the asynchronous code, rate-limited.
  • calls which come in within the sliding minute are performed until the configured rate per minute is reached, and extra calls are discarded
Parameters
action
Returns

void Reset ()
 Resets the sliding window of known calls.

Properties

int MaxCallsPerPeriod [get, set]
 The configured max-calls-per-minute, which can be modified at runtime.
TimeSpan Period [get]
 The configured period to rate limit over (read-only, for information only)
int CallsRunWithinLastPeriod [get]
 Reports the number of calls which have been successfully run during the last sliding window period.

Detailed Description

Constructor & Destructor Documentation

◆ RateLimiter() [1/2]

PeanutButter.Utils.RateLimiter.RateLimiter ( int maxCallsPerMinute)

Constructs the rate limiter with the provided maxCallsPerMinute.

Parameters
maxCallsPerMinute

◆ RateLimiter() [2/2]

PeanutButter.Utils.RateLimiter.RateLimiter ( int maxCallsPerPeriod,
TimeSpan period )

Configures the rate limiter with the provided max calls per provided period.

Parameters
maxCallsPerPeriod
period

Member Function Documentation

◆ Reset()

void PeanutButter.Utils.RateLimiter.Reset ( )

Resets the sliding window of known calls.

Implements PeanutButter.Utils.IRateLimiter.

◆ Run()

void PeanutButter.Utils.RateLimiter.Run ( Action action)

Runs the synchronous code, rate-limited.

  • calls which come in within the sliding minute are performed until the configured rate per minute is reached, and extra calls are discarded
Parameters
action

Implements PeanutButter.Utils.IRateLimiter.

◆ RunAsync()

async Task PeanutButter.Utils.RateLimiter.RunAsync ( Func< Task > action)

Runs the asynchronous code, rate-limited.

  • calls which come in within the sliding minute are performed until the configured rate per minute is reached, and extra calls are discarded
Parameters
action
Returns

Implements PeanutButter.Utils.IRateLimiter.

Property Documentation

◆ CallsRunWithinLastPeriod

int PeanutButter.Utils.RateLimiter.CallsRunWithinLastPeriod
get

Reports the number of calls which have been successfully run during the last sliding window period.

Implements PeanutButter.Utils.IRateLimiter.

◆ MaxCallsPerPeriod

int PeanutButter.Utils.RateLimiter.MaxCallsPerPeriod
getset

The configured max-calls-per-minute, which can be modified at runtime.

Implements PeanutButter.Utils.IRateLimiter.

◆ Period

TimeSpan PeanutButter.Utils.RateLimiter.Period
get

The configured period to rate limit over (read-only, for information only)

Implements PeanutButter.Utils.IRateLimiter.


The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/RateLimiter.cs