Skip to content

Instantly share code, notes, and snippets.

@s3u
Created March 13, 2012 20:14
Show Gist options
  • Save s3u/2031268 to your computer and use it in GitHub Desktop.
Save s3u/2031268 to your computer and use it in GitHub Desktop.
Fork/Join IO
var _ = require('underscore'),
http = require('http'),
URI = require('uri'),
async = require('async');
var sendReq = function (s, cb) {
// send a HTTP req, and pass error or result to the function arg
// content omitted for brevity
};
var sources = ['http://www.google.com', 'http://twitter.com', 'http://www.ebay.com'];
var funcs = [];
_.each(sources, function (source) {
funcs.push(function (s) {
return function (callback) {
sendReq(s, callback);
};
}(source));
});
async.parallel(funcs, function(err, res) {
// process results
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment