Skip to main content

bridge/classes/RateLimiter.md

Rate limiter that ensures a minimum interval between requests. Tasks run one at a time, in the order they were scheduled; the interval is measured between task starts.

Constructors​

Constructor​

new RateLimiter(requestsPerSecond): RateLimiter

Create a new rate limiter

Parameters​

ParameterTypeDescription
requestsPerSecondnumberMaximum requests per second

Returns​

RateLimiter

Throws​

GalaSDKError INVALID_BRIDGE_OPTION (requestsPerSecond) unless it is a number above zero (NaN would silently disable the limit)

Methods​

schedule()​

schedule<T>(task): Promise<T>

Schedule a task to run within rate limits. Tasks run serially, inside the chain, so concurrent callers can never exceed the limit.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
task() => Promise<T>The async task to execute

Returns​

Promise<T>

The result of the task; its failure (whatever it threw) as the rejection