EDA.HTTP.RateLimiter (EDA v0.3.0)

Copy Markdown View Source

Concurrent rate limiter for Discord REST API.

The GenServer acts as a coordinator — it never executes HTTP requests itself. It manages bucket state, a priority queue, and global rate limit tracking. Callers block on GenServer.call until the coordinator replies :ok, then execute the HTTP request in their own process (parallel).

Priority levels

  • :urgent (0) — bans, kicks, bulk-ban
  • :normal (1) — messages, edits (default)
  • :low (2) — reads, gets

Summary

Functions

Returns a specification to start this module under a supervisor.

Queues a request and executes fun when the rate limit allows.

Reports response headers to update bucket state.

Reports a 429 rate limit response.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

queue(method, path, fun, opts \\ [])

@spec queue(atom(), String.t(), (-> term()), keyword()) :: term()

Queues a request and executes fun when the rate limit allows.

The caller blocks until it receives permission, then fun.() runs in the caller's process. Handles 429 retries automatically.

Options

  • :priority — :urgent, :normal (default), or :low

report_headers(bucket, headers)

@spec report_headers(String.t(), [{String.t(), String.t()}]) :: :ok

Reports response headers to update bucket state.

report_rate_limited(bucket, retry_after_ms, global?)

@spec report_rate_limited(String.t(), integer(), boolean()) :: :ok

Reports a 429 rate limit response.

start_link(opts)