Skip to content

Instantly share code, notes, and snippets.

@arisolt
Created January 20, 2013 20:02
Show Gist options
  • Save arisolt/4581295 to your computer and use it in GitHub Desktop.
Save arisolt/4581295 to your computer and use it in GitHub Desktop.
var async = require('async'),
array1 = [1, 2, 3],
array2 = ['stuff'],
httprequest = require('request');
async.reduce(array1, array2, function (array2, item, callback) {
console.log("I've iterated " + item + "x");
process.nextTick(
function () {callback (array2.push(
function () {
var moreStuff = [];
httprequest("http://dummywebsite.com?id=" + item, function () {
var $ = cheerio.load(body);
var count = 0;
async.waterfall([
function (callback) {
$('strong').each(function(i, elem) {
count++;
});
callback(null, count);
},
function (count2, callback) {
$('strong').each(function(i, elem) {
moreStuff.push($(this).text());
if (i == count2 - 1) {
callback(null, moreStuff);
};
});
}],
function (err, result) {
return result;
});
});
}
))}
);
}, function (err, results){}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment