RateLimiter

interface RateLimiter

A RateLimiter provides logic necessary to limit the rate of execution of any sort of requests. For this purpose, a rate limiter distributes permits at a configurable rate. Permits can be acquired and do not have to be released.

RateLimiter implementations must specify the algorithms and configurations they use for distributing permits. This interface does not provide any guarantees about fairness but implementations may choose to.

Since

0.1.0

Inheritors

Functions

Link copied to clipboard
open suspend fun acquire()

Suspends the coroutine until a single permit was acquired.

abstract fun acquire(permits: Int): Flow<Int>

Returns a flow that emits the number of granted permits in intervals until all requested permits have been granted.

Link copied to clipboard
abstract suspend fun penalize()

Applies a penalty to this rate limiter for hitting the limit.