jhurliman/node-rate-limiter

Would this project be open to a PR adding asyncRemoveTokens?

sunknudsen opened this issue · 2 comments

I have been wrapping removeTokens in a promise (as suggested in #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)
    })
  })
}

Sure! I think this could be a member of RateLimiter

Done in 2.0.0