DelayRateLimiter

open class DelayRateLimiter(clock: Clock = Clock.System) : RateLimiter

A RateLimiter that proactively delays requests when the API rate limit is exhausted.

After each response, this implementation reads the X-RateLimit-Remaining and X-RateLimit-Reset headers to track the current window. When remaining reaches zero, throttle suspends the caller until the reset timestamp has passed before allowing the next request.

This prevents RateLimitExceededException under normal single-instance usage. If multiple dev.pubgkt.PubgApi instances share the same API key, 429 responses can still occur and will be surfaced as RateLimitExceededException.

This implementation is not designed for high-concurrency scenarios where many coroutines fire requests simultaneously.

See also

Inheritors

Constructors

Link copied to clipboard
constructor(clock: Clock = Clock.System)
constructor()

kotlin.time.Clock is not exported to JavaScript. This secondary constructor allows JavaScript consumers to instantiate DelayRateLimiter

Functions

Link copied to clipboard
open override fun onResponse(limit: Int?, remaining: Int?, reset: Long?)

Called after every response to update internal state from rate-limit headers. Any parameter may be null if the corresponding header was absent.

Link copied to clipboard
open suspend override fun throttle()

Called before each outbound request. Implementations should suspend here if the rate limit has been (or is about to be) reached.