Package Exports
- bottleneck
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bottleneck) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
bottleneck
Bottleneck is a very simple and efficient Asynchronous Rate Limiter for Node.JS. When dealing with services with limited resources, it's important to ensure that they don't become overloaded with requests. Bottleneck handles that case in a clean and simple way.
#Installation
Node
npm install bottleneckBrowser
<script type="text/javascript" src="bottleneck.min.js"></script>#Usage
Most APIs have a rate limit. For example, the Reddit.com API limits programs to 1 request every 2 seconds.
var Bottleneck = require("bottleneck"); //Ignore if Browser
// Wait at least 2000ms between each request. Never more than 1 request running at a time.
var limiter = new Bottleneck(1, 2000);new Bottleneck(maxNb, minTime);
- maxNb : How many requests can be executing at the same time. 0 means unlimited.
- minTime : How long to wait between each new request.
Instead of doing
someAsyncCall(arg1, arg2, callback);You do
limiter.submit(function(cb){
someAsyncCall(ar1, arg2, cb);
}, callback);And now you can be assured that someAsyncCall will follow the rate guidelines!
###stopAll
limiter.stopAll();stopAll cancels all requests not already running and prevents new requests from being submitted.
##TODO
Change the API to
limiter.submit(someAsyncCall, ar1, arg2, callback);