Skip to main content

Class RateLimitBucket

Inheritance
System.Object
Inherited Members
Show
Syntax
public class RateLimitBucket

Constructors

RateLimitBucket(Double, RateLimitBucket.RefillConfig)

Declaration
public RateLimitBucket(double now, RateLimitBucket.RefillConfig config)
Parameters
TypeNameDescription
System.Doublenow
Mirage.SocketLayer.RateLimitBucket.RefillConfigconfig

Fields

Config

Declaration
public readonly RateLimitBucket.RefillConfig Config

Properties

Tokens

Declaration
public float Tokens { get; }

Methods

UseTokens(Double, Int32)

Refills the bucket based on time passed and then consumes tokens. Useful for rarely used buckets that need to be up-to-date at the moment of a call.

Declaration
public bool UseTokens(double now, int amount)
Parameters
TypeNameDescription
System.Doublenow
System.Int32amount
Returns
TypeDescription
System.Boolean

CheckRefill(Double)

Refills tokens based on config. If the bucket is full, it will reset the refill timer to 'now'.

Declaration
public void CheckRefill(double now)
Parameters
TypeNameDescription
System.DoublenowCurrent time in seconds

UseTokens(Int32)

Subtracts cost from token count. Tokens can go negative to penalize burst spam.

Declaration
public bool UseTokens(int cost)
Parameters
TypeNameDescription
System.Int32cost
Returns
TypeDescription
System.BooleanTrue if the bucket is empty (negative), indicating the rate limit was exceeded.

IsEmpty()

Returns true if tokens is negative (indicating we ran out and are currently in debt).

Declaration
public bool IsEmpty()
Returns
TypeDescription
System.Boolean