Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting per-use() forced requests? #14

Open
headlessme opened this issue Aug 29, 2023 · 1 comment
Open

Supporting per-use() forced requests? #14

headlessme opened this issue Aug 29, 2023 · 1 comment

Comments

@headlessme
Copy link

We have some endpoints that are rate limited but we always want to the requests to succeed even if that sends the token balance negative. Currently we'd need to instantiate two RollingLimit classes with different options and manage which instance was applied to the different endpoints.
Would you be open to adding a new parameter to the use() signature to specify the value for force? e.g. use(id, cost, force)

@STRML
Copy link
Contributor

STRML commented Sep 5, 2023

Typically, if you already know the value of force at call-time, then you should be able to interpret the result resolved from use() in the same way. For instance:

async function checkLimitForRoute(route, uid, cost) {
  const force = FORCE_ROUTES.includes(route);
  const limit = await limiter.use(uid, cost);
  // ...
  if (limit.rejected && !force) {
    // reject request
  } else {
    // allow request
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants