rateLimiter

fun rateLimiter(maxRate: Long, init: RateLimiterBuilder.() -> Unit = {}): 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)

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
}
}