ProtoRune.HTTPClient.RateLimiter (proto_rune v0.5.1)

Copy Markdown

Tracks outgoing requests per key (usually the target host) in fixed one-minute windows and throttles callers once a configurable limit is reached.

Counts are kept in an ETS table so no process needs to be started. When the limit for the current window is exceeded, the caller sleeps until the next window starts.

Summary

Functions

Registers a request for key, sleeping until the next window when the per-minute limit for the current window has been reached.

Functions

await_turn(key, opts \\ [])

Registers a request for key, sleeping until the next window when the per-minute limit for the current window has been reached.

Options

  • :requests_per_minute - the limit for key. nil or false disables throttling and tracking.
  • :now_fun - zero-arity function returning the current time in milliseconds. Defaults to System.monotonic_time/1.
  • :sleep_fun - one-arity function used to wait, defaults to Process.sleep/1.

Returns :ok once the request may proceed.