Rate limiting (throttling) implementation for Promises on Node.js
Install:
npm install q-ratelimit
Limit frequency of promise fulfilling:
var throttle = require('q-ratelimit')(2000); /* rateInMilliseconds */
var startTime = Date.now();
for (var i = 0; i < 10; i++) {
throttle().then(function() { console.log(Date.now() - startTime); }).done();
}
// example output:
// 11
// 2007
// 4007
// 6008
// 8011
// 10014
// 12016
// 14018
// 16020
// 18022
MIT
Note: q-ratelimit and promise-ratelimit are sister modules based on the same original code.