0.2.0 • Published 7 years ago

function-threshold v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

function-threshold

NPM version

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');