IntervalRateLimiter

A RateLimiter that restricts the number of consume invocations in intervals to a given limit. Exceeding this limit results in suspension until the next interval.

Inheritors

Properties

Link copied to clipboard
abstract val interval: Duration

The Duration of each interval.

Link copied to clipboard
abstract val limit: Int

The maximum number of consume invocations allowed for each interval.

Functions

Link copied to clipboard
abstract suspend override fun consume()

Acquires a permit for a single action. Suspends until the next interval if limit permits have already been acquired in the current interval.

Link copied to clipboard
inline suspend fun <T> RateLimiter.consume(action: () -> T): T

Acquires a permit for a single action. Suspends if necessary until the permit would not exceed the maximum frequency of permits.