@vampyreio/ratelimiter-lib
v0.3.0
Published
Leaky & Token Bucket Rate Limiter
Downloads
4
Readme
Rate-Limiter-Lib
Simple event-based rate limiting that can used by your server or my schildwall-gateway as middleware. It stops the dripper when to requests are in the queue and restarts when a new entity is pushed.
It will run until all requests are answered and only then stop running!
Leaky Bucket Limiter
import {LeakyBucketRateLimiter} from '@vampyreio/ratelimiter-lib';
const rateLimiter = new LeakyBucketRateLimiter({
quanitityOfDrips: 1,
timeBetweenDrips: 100,
});
async () => {
// test rate limits that are not taken care of
this.rateLimiter.wait();
this.rateLimiter.wait();
this.rateLimiter.wait();
// resolves when the rate limiter lets it pass through
const start = Date.now();
return await this.rateLimiter.wait();
const stop = Date.now();
}();
Options
quantityOfDrips
: how many requests are let through in réach tick.
timeBetweenDrips
: how long the limiter will wait before passing through the next drips
Token Bucket Limiter
Not yet implemented