Created
May 21, 2013 18:15
-
-
Save aearly/5621990 to your computer and use it in GitHub Desktop.
async.mapFunctions - map a list of functions to a single item
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
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