javascript - using _.map and async.map together -
i'm using both _.map , async.map in node portion of application i'm working on. i'm running confusion while using these libraries together.
i have array of arrays called results looks this:
[[1, 2, 3], [2, 4, 6], [1, 3, 5]] i use _.map access each inner array, , async.map make api call each value within each of these inner arrays. use results of api call replace each integer within inner arrays object.
so @ end array of arrays of integers instead array of arrays of objects based on api call results.
[[{id: 1, email: 'test@example.com', state: 'active'}], ...] this current code have, , believe i'm on right path. first console.log gives me object i'm aiming for, second returns integer:
_.map(results, function(result) { async.map(result, function(user, callback) { db.users.getbyid(user, function(err, userdetails) { if (err) { callback(null, null); } else { user = _.pick(userdetails, 'id', 'email', 'state'); console.log(user); } }); console.log(user); }) });
from docs:
_.map(results, function(result) { async.map(result, function(user, callback) { db.users.getbyid(user, function(err, userdetails) { callback(err, _.pick(userdetails, 'id', 'email', 'state')); }); }, function(err, users){ // here have populated array of (arrays of) users }) }); but you'll find promise.all more expressive in regard.
Comments
Post a Comment