Created
July 8, 2015 19:39
-
-
Save graywolf336/ea5ab25be6599e4d58e7 to your computer and use it in GitHub Desktop.
Rate Limiter w/ Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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