Tinkex.RateLimiter (Tinkex v0.3.4)

View Source

Shared backoff state per {base_url, api_key} combination.

Summary

Functions

Clear any active backoff window.

Get or create the limiter for a {base_url, api_key} tuple.

Set a backoff window in milliseconds.

Determine whether the limiter is currently in a backoff window.

Block until the backoff window has passed.

Types

limiter()

@type limiter() :: :atomics.atomics_ref()

Functions

clear_backoff(limiter)

@spec clear_backoff(limiter()) :: :ok

Clear any active backoff window.

for_key(arg)

@spec for_key({String.t(), String.t() | nil}) :: limiter()

Get or create the limiter for a {base_url, api_key} tuple.

set_backoff(limiter, duration_ms)

@spec set_backoff(limiter(), non_neg_integer()) :: :ok

Set a backoff window in milliseconds.

should_backoff?(limiter)

@spec should_backoff?(limiter()) :: boolean()

Determine whether the limiter is currently in a backoff window.

wait_for_backoff(limiter)

@spec wait_for_backoff(limiter()) :: :ok

Block until the backoff window has passed.