Foundation.RateLimit.BackoffWindow (foundation v0.2.1)

Copy Markdown View Source

Shared backoff windows keyed by arbitrary identifiers.

Summary

Functions

Clear any active backoff window.

Return the default registry (anonymous ETS table).

Get or create a limiter for the given key in the default registry.

Get or create a limiter for the given key in the provided registry.

Create a new registry. Use name: :my_table for a named ETS table.

Set a backoff window in milliseconds.

Determine whether a limiter is currently in a backoff window.

Block until the backoff window has passed.

Types

limiter()

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

registry()

@type registry() :: :ets.tid() | atom()

Functions

clear(limiter)

@spec clear(limiter()) :: :ok

Clear any active backoff window.

default_registry()

@spec default_registry() :: registry()

Return the default registry (anonymous ETS table).

for_key(key)

@spec for_key(term()) :: limiter()

Get or create a limiter for the given key in the default registry.

for_key(registry, key)

@spec for_key(registry(), term()) :: limiter()

Get or create a limiter for the given key in the provided registry.

new_registry(opts \\ [])

@spec new_registry(keyword()) :: registry()

Create a new registry. Use name: :my_table for a named ETS table.

set(limiter, duration_ms, opts \\ [])

@spec set(limiter(), non_neg_integer(), keyword()) :: :ok

Set a backoff window in milliseconds.

should_backoff?(limiter, opts \\ [])

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

Determine whether a limiter is currently in a backoff window.

wait(limiter, opts \\ [])

@spec wait(
  limiter(),
  keyword()
) :: :ok

Block until the backoff window has passed.