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

Start with a full tokenBucket #41

Closed JelteF closed 6 years ago

JelteF commented 7 years ago

I ran into issues where after creating a bucket on demand for new customers the customer would get rate limited right away. This was caused by the fact that a new bucket is empty. This PR changes the code so a new bucket will start full.

jhurliman commented 6 years ago

This is a good change, but it would definitely change the default behavior of the lib (see the failed unit test) and require a major version bump. I would recommend either adding an additional parameter to the TokenBucket constructor, something like startFull or initialContent, or just set myBucket.content = myBucket. bucketSize; after instantiating.

I'm going to close this PR for now; please resubmit if you want to go for the first approach.