Created
January 19, 2013 23:49
-
-
Save geNAZt/4575866 to your computer and use it in GitHub Desktop.
This file contains 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 httprequest = require('request'), | |
async = require('async'), | |
requests = [], | |
page, | |
maxPage = 50, | |
url = "http://www.google.com/?p="; | |
//Callback which each Request hits | |
function performAfterLoadAttempt(error, response, body) { | |
"use strict"; | |
//Log the Body | |
console.log(body); | |
} | |
function addToRequestArray(page) { | |
"use strict"; | |
requests.push(function () { | |
httprequest(url + page, performAfterLoadAttempt); | |
}); | |
} | |
//Fill the Array with one Function per Page | |
for (page = 0; page < maxPage; page += 1) { | |
addToRequestArray(page); | |
} | |
//And now execute them all together | |
async.parallel(requests); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment