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

Wait from final request of the interval rather than the first #91

Open GunaShekar02 opened 2 years ago

GunaShekar02 commented 2 years ago

Currently, the number of seconds to wait is this.curIntervalStart + this.tokenBucket.interval - now. Instead I'd like to have the limiter wait for just this.tokenBucket.interval instead.

Example:- Consider rate limit to be 10 per minute. Assume each request takes 2 seconds to execute.

curIntervalStart = 0th second
Request 1 = 2nd second
Request 2 = 4th second
....
Request 10 = 20th second

The current system would wait and restart at the 60th second(0+60), but I'd like it to wait and restart at the 80th second(20+60).

If this can be done, I'd be happy to help implement this.