Skip to content

Instantly share code, notes, and snippets.

@aearly
Created May 21, 2013 18:15
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 aearly/5621990 to your computer and use it in GitHub Desktop.
Save aearly/5621990 to your computer and use it in GitHub Desktop.
async.mapFunctions - map a list of functions to a single item
function asyncify(fn) {
return function (option, callback) {
var res;
try {
res = fn(option);
} catch (err) {
return callback(err);
}
callback(null, res);
}
}
_.mapObj = _.map(obj, fn).zip(_.keys(obj))
function mapFunctions(item, functions, callback) {
var results = [];
async.eachSeries(functions, function (fn, cb) {
fn(item, function (err, result) {
if (err) {return callback(err); }
results.push(result);
cb(null);
});
}, function (err) {
if (err) {return callback(err); }
callback(null, results);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment