tokenbucket
Advanced tools
Comparing version
{ | ||
"name": "tokenbucket", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A flexible rate limiter using different variations of the Token Bucket algorithm, with hierarchy support, and optional persistence in Redis. Useful for limiting API requests, or other tasks that need to be throttled.", | ||
@@ -30,26 +30,24 @@ "keywords": [ | ||
"test": "gulp test", | ||
"coveralls": "npm run-script test && ./node_modules/coveralls/bin/coveralls.js < coverage/lcov.info" | ||
"coveralls": "gulp coveralls" | ||
}, | ||
"dependencies": { | ||
"bluebird": "2.9.14" | ||
"bluebird": "^2.9.14" | ||
}, | ||
"devDependencies": { | ||
"chai": "1.9.1", | ||
"chai-as-promised": "4.3.0", | ||
"coffee-script": "1.8.0", | ||
"coveralls": "^2.11.2", | ||
"gulp": "3.8.6", | ||
"gulp-coffee": "2.1.1", | ||
"chai": "^1.9.1", | ||
"chai-as-promised": "^4.3.0", | ||
"coffee-script": "^1.8.0", | ||
"gulp": "^3.8.6", | ||
"gulp-coffee": "^2.1.1", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-istanbul": "0.5.0", | ||
"gulp-jsdoc-to-markdown": "^0.1.6", | ||
"gulp-markdox": "^0.1.1", | ||
"gulp-mocha": "2.0.0", | ||
"gulp-plumber": "1.0.0", | ||
"gulp-util": "3.0.0", | ||
"gulp-watch": "4.1.1", | ||
"gulp-coveralls": "^0.1.3", | ||
"gulp-istanbul": "^0.5.0", | ||
"gulp-mocha": "^2.0.0", | ||
"gulp-plumber": "^1.0.0", | ||
"gulp-util": "^3.0.0", | ||
"gulp-watch": "^4.1.1", | ||
"jsdoc-to-markdown": "^0.6.4", | ||
"mocha": "2.0.0", | ||
"sinon": "1.9.1", | ||
"sinon-chai": "2.5.0" | ||
"mocha": "^2.0.0", | ||
"sinon": "^1.9.1", | ||
"sinon-chai": "^2.5.0" | ||
}, | ||
@@ -56,0 +54,0 @@ "engines": { |
[](https://david-dm.org/jesucarr/tokenbucket) | ||
[](https://david-dm.org/jesucarr/tokenbucket#info=devDependencies) | ||
[](https://travis-ci.org/jesucarr/tokenbucket) | ||
[](https://coveralls.io/r/jesucarr/tokenbucket) | ||
[](https://npmjs.org/package/tokenbucket) | ||
@@ -135,3 +135,3 @@ | ||
console.log('10 tokens removed, ' + remainingTokens + 'tokens left'); | ||
// Do triple API call | ||
// make triple API call | ||
}).catch(function (err) { | ||
@@ -158,5 +158,5 @@ console.log(err) | ||
if (tokenBucket.removeTokensSync(50)) { | ||
// The tokens were removed | ||
// the tokens were removed | ||
} else { | ||
// The tokens were not removed | ||
// the tokens were not removed | ||
} | ||
@@ -166,3 +166,3 @@ ``` | ||
#### tokenBucket.save() ⇒ <code>Promise</code> | ||
Saves the bucket lastFill and tokensLeft to Redis. | ||
Saves the bucket lastFill and tokensLeft to Redis. If it has any parents with `redis` options, they will get saved too. | ||
@@ -180,3 +180,3 @@ **Kind**: instance method of <code>[TokenBucket](#exp_module_tokenbucket--TokenBucket)</code> | ||
tokenBucket.loadSaved().then(function () { | ||
// Now the bucket has the state it had last time we saved it. | ||
// now the bucket has the state it had last time we saved it | ||
return tokenBucket.removeTokens().then(function() { | ||
@@ -199,3 +199,3 @@ // make API call | ||
#### tokenBucket.loadSaved() ⇒ <code>Promise</code> | ||
Loads the bucket lastFill and tokensLeft as it was saved in Redis | ||
Loads the bucket lastFill and tokensLeft as it was saved in Redis. If it has any parents with `redis` options, they will get loaded too. | ||
@@ -214,2 +214,18 @@ **Kind**: instance method of <code>[TokenBucket](#exp_module_tokenbucket--TokenBucket)</code> | ||
## Development and Contributing | ||
The source code is in CoffeeScript, to compile automatically when you save, run | ||
gulp | ||
Documentation is inline, using [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown). To update the README.md file just run | ||
gulp doc | ||
Contributions are welcome! | ||
## Credits | ||
Originally inspired by [limiter](https://github.com/jhurliman/node-rate-limiter) | ||
## License | ||
@@ -216,0 +232,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82856
0.82%16
-11.11%248
6.9%+ Added
- Removed
Updated