TokenBucketRateLimiter

class TokenBucketRateLimiter(bucketSize: Int = 300, refillDuration: Duration = 1.minutes) : RateLimiter

A RateLimiter implementation that uses the token bucket algorithm.

Since

0.4.0

Parameters

bucketSize

the size of the bucket

refillDuration

the maximum time until the bucket is filled after being fully depleted

Constructors

Link copied to clipboard
constructor(bucketSize: Int = 300, refillDuration: Duration = 1.minutes)

Functions

Link copied to clipboard
open suspend fun acquire()

Suspends the coroutine until a single permit was acquired.

open override 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
open suspend override fun penalize()

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