function-threshold
v0.2.0
Published
Limit the amount of times a function can be called in a specific timeframe and throw an error if the limit is exceeded.
Downloads
17
Readme
function-threshold
Limit the amount of times a function can be called in a specific timeframe and throw an error if the limit is exceeded.
Installation
with npm
npm install function-threshold
with yarn
yarn add function-threshold
Example
var FunctionThreshold = require('function-threshold');
function myFunction(suffix) {
console.log('hooray, hello ' + suffix + '!');
}
// limit to 5 executions per 10 seconds (10.000 ms)
var threshold = new FunctionThreshold(myFunction, 5, 10000);
// call the function somewhere. It will throw an exception if limit is exceeded
threshold.call('world');