JSPM

  • Created
  • Published
  • Downloads 2335360
  • Score
    100M100P100Q195937F
  • License MIT

Async rate limiter

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 bottleneck

Browser

<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 running at the same time. 0 means unlimited.
  • minTime : How long to wait between each request.

Instead of doing

someAsyncCall(arg1, arg2, callback);

You do

limiter.submit(someAsyncCall, ar1, arg2, callback);

And now you can be assured that someAsyncCall will follow the rate guidelines!

###stopAll

limiter.stopAll();

stopAll cancels all queued up requests and prevents additonal requests from being submitted.