Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created January 19, 2013 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geNAZt/4575550 to your computer and use it in GitHub Desktop.
Save geNAZt/4575550 to your computer and use it in GitHub Desktop.
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