RateLimiter
class RateLimiter(val permits: Int, val per: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)
A sliding-window rate limiter that grants at most permits acquisitions within any window of length per.
Algorithm: the limiter remembers the time mark of each recent acquisition and grants a permit whenever fewer than permits marks are younger than per.
acquire and tryAcquire are coroutine-safe: shared state is guarded by a Mutex, and a coroutine suspended in acquire holds the mutex while it waits, so permits are granted to waiters in arrival order.
Constructors
Link copied to clipboard
constructor(permits: Int, per: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)