0.3.0 • Published 5 years ago

@vampyreio/ratelimiter-lib v0.3.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

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

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago