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

Question: Multiple limits #51

Closed earthiverse closed 6 years ago

earthiverse commented 6 years ago

Is it possible to have two limits? For example, I want to limit 1 request per second, to a maximum of 1000 per hour.

Can I do that using this package?

earthiverse commented 6 years ago

You can just make two different limits and nest them.

var limiter1 = new RateLimiter(1, 'second')
var limiter2 = new RateLimiter(600, 'hour')
limiter1.removeTokens(1, function () {
  limiter2.removeTokens(1, function () {
    // Code goes here
  })
})