glimiter

Package Version Hex Docs

gleam add glimiter
import birl/duration
import glimiter

pub fn main() {
  // Creating our limiter to allow 1 request per minute for a given request key
  let limiter = new_limiter(1, duration.minutes(1))

  // When the request arrives
  let limiter = update(limiter, "RequestKey")

  // Using the guard so that when the limit is exceeded, we return the error
  use <- limit_guard(
    when: limiter,
    with: "RequestKey",
    return: Error("Request limit exceeded"),
  )

  Ok("Response")
}

Further documentation can be found at https://hexdocs.pm/glimiter.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

More Examples

Search Document