UNPKG

alinex-async

Version:

An extended version of the async library.

71 lines (65 loc) 1.97 kB
(function() { var async; async = require('async'); module.exports.mapOf = function(obj, iterator, cb) { var keys; if (typeof obj !== 'object') { return cb(new Error("mapOf only works on objects")); } keys = Object.keys(obj); return async.map(keys, function(key, cb) { return iterator(obj[key], key, cb); }, function(err, results) { var i, map, num, ref; if (err) { return cb(err); } map = {}; for (num = i = 0, ref = keys.length - 1; 0 <= ref ? i <= ref : i >= ref; num = 0 <= ref ? ++i : --i) { map[keys[num]] = results[num]; } return cb(null, map); }); }; module.exports.mapOfLimit = function(obj, limit, iterator, cb) { var keys; if (typeof obj !== 'object') { return cb(new Error("mapOf only works on objects")); } keys = Object.keys(obj); return async.mapLimit(keys, limit, function(key, cb) { return iterator(obj[key], key, cb); }, function(err, results) { var i, map, num, ref; if (err) { return cb(err); } map = {}; for (num = i = 0, ref = keys.length - 1; 0 <= ref ? i <= ref : i >= ref; num = 0 <= ref ? ++i : --i) { map[keys[num]] = results[num]; } return cb(null, map); }); }; module.exports.mapOfSeries = function(obj, iterator, cb) { var keys; if (typeof obj !== 'object') { return cb(new Error("mapOf only works on objects")); } keys = Object.keys(obj); return async.mapSeries(keys, function(key, cb) { return iterator(obj[key], key, cb); }, function(err, results) { var i, map, num, ref; if (err) { return cb(err); } map = {}; for (num = i = 0, ref = keys.length - 1; 0 <= ref ? i <= ref : i >= ref; num = 0 <= ref ? ++i : --i) { map[keys[num]] = results[num]; } return cb(null, map); }); }; }).call(this); //# sourceMappingURL=mapof.map