Skip to content

Instantly share code, notes, and snippets.

@graywolf336
Created July 8, 2015 19:39
Show Gist options
  • Save graywolf336/ea5ab25be6599e4d58e7 to your computer and use it in GitHub Desktop.
Save graywolf336/ea5ab25be6599e4d58e7 to your computer and use it in GitHub Desktop.
Rate Limiter w/ Async
var limiter = new RateLimiter(5, 15000);
async.each([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], function(i, callback) {
limiter.removeTokens(1, function(err, remainingRequests) {
if(err) {
callback(err);
}else {
console.log(i);
callback();
}
})
}, function(error) {
console.log('Done or error:', error);
});
@graywolf336
Copy link
Author

Limits the output to log something to the console every 15 seconds, or around there.

Rate Limiter: https://github.com/jhurliman/node-rate-limiter
Async: https://github.com/caolan/async#each

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment