ConcurrentDelayRateLimiter

class ConcurrentDelayRateLimiter(clock: Clock = Clock.System) : DelayRateLimiter

A DelayRateLimiter variant that serializes throttle calls across coroutines.

This implementation preserves the proactive waiting behavior of DelayRateLimiter, but wraps throttle in a Mutex so only one coroutine evaluates and applies the wait logic at a time.

Use this limiter when many coroutines can issue requests concurrently from the same dev.pubgkt.PubgApi instance and you want to avoid race conditions around shared rate-limit state.

Like DelayRateLimiter, this class relies on rate-limit headers provided via onResponse. It reduces local contention issues, but cannot prevent 429 responses caused by external consumers using the same API key.

See also

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 ConcurrentDelayRateLimiter

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.