RateLimiter

interface RateLimiter

A client-side utility that can limit the rate of transactions. This limiter is usually backed by some set of permits which refill over time. This kind of rate limiting is often used in conjunction with a retry algorithm, especially when it may be desirable to delay the initial attempt of a transaction (instead of just delaying subsequent attempts).

Callers should invoke acquire with the cost of their transaction prior to executing. If there are not enough permits available currently, the call may delay.

Once the transaction is completed, callers should invoke update and indicate the type of error (if any) the transaction yielded. The rate limiter may use this information to adjust the number of available permits or the rate of permit renewal.

Inheritors

Types

Link copied to clipboard
interface Config

Properties

Link copied to clipboard

Functions

Link copied to clipboard
abstract suspend fun acquire(cost: Int)

Acquire a "permit" to conduct a transaction. If not enough permits are available, this method may delay.

Link copied to clipboard
abstract suspend fun update(errorType: RetryErrorType?)

Update the rate limiter with the result of a transaction. The rate limiter may use this information to adjust the number of available permits or the rate at which permits refill.