Created
March 13, 2012 20:14
-
-
Save s3u/2031268 to your computer and use it in GitHub Desktop.
Fork/Join IO
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 _ = 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