derwine / limitor

A simple class based rate limiter / de-bouncer for JavaScript applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Limitor is a class based implementation of a function rate limiter / debouncer. It uses setInterval to create a running clock used to enforce the rate, and reset every x millisecons. See the source for details.

Basic Usage

Create an instance of Limitor. *Limitor(maxOperations, maxInterval, verbose=false)

var lm = new Limitor(3, 2000, true);
lm.init();

Basic function to execute.

let addNums = (x, y) => {
result = x + y;
console.log(result);
}

Run function through the lm instance.

lm.exec(() => {
    addNums(2,3);
})

About

A simple class based rate limiter / de-bouncer for JavaScript applications

License:MIT License


Languages

Language:JavaScript 100.0%