Skip to content

Instantly share code, notes, and snippets.

@robraux
Created October 14, 2015 19:07
Show Gist options
  • Save robraux/ffba98e810568a5559b6 to your computer and use it in GitHub Desktop.
Save robraux/ffba98e810568a5559b6 to your computer and use it in GitHub Desktop.
Keep an API flooded, but not overwelmed
var request = require('request')
var async = require('async')
var url = "https://yourapi"
// status codes and the number of results
var results = {200 : 0, 500: 0};
var requestIt = function(cb) {
request(url, function (error, response, body) {
if(error) {
console.log(error)
return cb()
}
results[response.statusCode]++
return cb()
})
}
var me = function() {
async.forever(
function(next) {
async.parallel([ requestIt, requestIt, requestIt, requestIt], function(err) { return next(); })
},
function(err) {
if(err) {
console.log(err)
}
}
)
}
me()
// give data every second regarding what's being run
setInterval(function() { console.dir(results); }, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment