0

I have several functions that look like this one:

  var functions = {
    prices: function prices(callback) {
      Price.findAll({}).then(function(results){
        callback(null, results);
      }).catch(function(error){
        callback(error);
      });
    }
  };
  
  functions.language = function language(callback){
    Language.findById(assistant.language).then(function(result){
      callback(null, result);
    }).catch(function(error){
      callback(error);
    });
  };
  
  async.parallel(functions, function(err, results){
    if(err) return callback(err);
    
    ...
  });
}

And I pass them as one object to async.parallel(). When I run the code, I get this error: Unhandled rejection Error: Callback was already called.

I know what it means, but I don't understand why.

molerat
  • 946
  • 4
  • 15
  • 43
  • Can you post the full code? `async.parallel()` takes an array of functions as an argument, are you sure you are only passing in `callback` once? – doublesharp Dec 15 '16 at 00:20
  • @doublesharp Updated my code snippet – molerat Dec 15 '16 at 00:27
  • `callback` is undefined within the callback in `async.parallel`. – doublesharp Dec 15 '16 at 00:35
  • Nope. Sorry, added the line to this question just now.. The console shows the error in the catch callback of the Language function. – molerat Dec 15 '16 at 00:55
  • You are passing in an object with properties that are functions but it takes an array of functions as the first argument. – doublesharp Dec 15 '16 at 02:26
  • Nope, you can use it that way too in order to have the results in a logical object. See https://caolan.github.io/async/docs.html#parallel – molerat Dec 15 '16 at 22:34
  • Trust me, try using a static analysis tool. – doublesharp Dec 15 '16 at 23:15
  • I know this is a bit late, but for anyone else with the same issue, I found a solution at [http://stackoverflow.com/questions/32708816/problems-with-sequelize-promises-and-normal-node-js-callbacks](http://stackoverflow.com/questions/32708816/problems-with-sequelize-promises-and-normal-node-js-callbacks) – rodp82 Feb 13 '17 at 23:58

0 Answers0