jhurliman / node-rate-limiter

A generic rate limiter for node.js. Useful for API clients, web crawling, or other tasks that need to be throttled
MIT License
1.51k stars 135 forks source link

Would this project be open to a PR adding asyncRemoveTokens? #63

Closed sunknudsen closed 3 years ago

sunknudsen commented 4 years ago

I have been wrapping removeTokens in a promise (as suggested in https://github.com/jhurliman/node-rate-limiter/issues/52) for a while.

Feels like it would be clean and useful if we implemented an asyncRemoveTokens method.

function asyncRemoveTokens(count: number, rateLimiter: RateLimiter) {
  return new Promise((resolve, reject) => {
    rateLimiter.removeTokens(count, (error, remainingRequests) => {
      if (error) return reject(error)
      resolve(remainingRequests)
    })
  })
}
jhurliman commented 3 years ago

Sure! I think this could be a member of RateLimiter

jhurliman commented 3 years ago

Done in 2.0.0