rateLimiter
Creates a RateLimiter instance with the specified maxRate.
Parameters
maxRate
the maximum rate at which tokens can be consumed
init
the builder configuration
To create a rate limiter that allows 5 requests per second:
val rateLimiter = rateLimiter(maxRate = 5)
Content copied to clipboard
To create a rate limiter that allows 5 requests per second, expiring keys unused for 2 hours:
val rateLimiter = rateLimiter(maxRate = 5) {
stateStorage = memoryStateStorageWithEviction {
ttlAfterLastAccess = 2.hours
}
}
Content copied to clipboard