peterkhayes/rolling-rate-limiter

Promisify rate limiter

weeco opened this issue · 4 comments

weeco commented

Hey,
is it possible to use this rate limiter in a Promise based way? Usually I promisify libraries which use callbacks with bluebird, but I am not sure how I am supposed to do this here.

Should be relatively straightforward:

const limiter = Bluebird.promisify(RateLimiter(redisConfig))

limiter(userId)
  .then((timeLeft) => {
    /* 0 if unblocked, >0 if blocked; see readme */
  })
  .catch((err) => {
    /* handle redis error */ 
  })
simlu commented

+1

util.promisify also works here if you prefer native promises.

There is a new version of this library out. You can see the release notes here. One of the changes is that all methods are promise-based now.