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
| Type | Name | Description |
|---|---|---|
| System.Double | now | |
| Mirage.SocketLayer.RateLimitBucket.RefillConfig | config |
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
| Type | Name | Description |
|---|---|---|
| System.Double | now | |
| System.Int32 | amount |
Returns
| Type | Description |
|---|---|
| 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
| Type | Name | Description |
|---|---|---|
| System.Double | now | Current 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
| Type | Name | Description |
|---|---|---|
| System.Int32 | cost |
Returns
| Type | Description |
|---|---|
| System.Boolean | True 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
| Type | Description |
|---|---|
| System.Boolean |