Package-level declarations

Types

Link copied to clipboard
abstract class AbstractIntervalRateLimiter(val limit: Int, val interval: Duration) : IntervalRateLimiter

Abstract base class for implementing IntervalRateLimiter.

Link copied to clipboard

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.

Link copied to clipboard
interface RateLimiter

A rate limiter that limits the number of consume invocations that can be made over a certain period.

Functions

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.

Link copied to clipboard
fun IntervalRateLimiter(limit: Int, interval: Duration, timeSource: TimeSource = TimeSource.Monotonic): IntervalRateLimiter

Creates an implementation of IntervalRateLimiter that uses a TimeSource for measuring intervals.

fun IntervalRateLimiter(limit: Int, interval: Duration, clock: Clock): IntervalRateLimiter

Creates an implementation of IntervalRateLimiter that uses a Clock for measuring intervals.