Created
October 14, 2015 19:07
-
-
Save robraux/ffba98e810568a5559b6 to your computer and use it in GitHub Desktop.
Keep an API flooded, but not overwelmed
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 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