Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Result null in async.parallel

Result null in async.parallel

Problem

Hi I am trying to play around with async.parallel and here is my code for the call. When I go and checkout the console the results are undefined. This is pretty straight forward so i know I must be goofing up something simple.

async.parallel([
   function(cb){
      Challenges.find({}, function(err, docs){
         cb(err, docs);
      });
   },
   function(cb){
      Challenges.find({}, function(err, docs){
         cb(err, docs);
      });
   }
], function(results){
   console.log("results "+util.inspect(results)); 

});

btw, I logged docs in each of the calls before the callback to make sure I am getting back data and am able to see the docs returned.

Problem courtesy of: Hans

Solution

The result callback for async.parallel has 2 parameters, not one. The first is err.

async.parallel([
  function(cb){
    Challenges.find({}, function(err, docs){
      cb(err, docs);
    });
  },
  function(cb){
    Challenges.find({}, function(err, docs){
      cb(err, docs);
    });
  }
], function(err, results){
   console.log("results "+util.inspect(results)); 
});
Solution courtesy of: loganfsmyth

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Result null in async.parallel

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×