0

I am trying to return the final value of async.map instead of console.logging. Unfortunately the return statement is never run:

var square = function (num, doneCallback) {
  return doneCallback(null, num * num);
};
// **Works**
async.map([1, 2, 3, 4], square, function (err, results) {

  console.log("Finished!");
  console.log(results);
  // return results;
});


// **Not Working**
async.map([1, 2, 3, 4], square, function (err, results) {

  console.log("Finished!");
  // console.log(results);
  return results;
});

How can I return results instead of using console.log?

Barmar
  • 741,623
  • 53
  • 500
  • 612
HelloWorld
  • 10,529
  • 10
  • 31
  • 50
  • 1
    Why are you using `async.map` if you want to return the results? Use `Array.prototype.map` – Barmar Aug 08 '14 at 03:51
  • The `return` statement is run. But `async.js` is intended for use in asynchronous code, where the return value doesn't get used, so it doesn't do anything with it. – Barmar Aug 08 '14 at 03:52
  • BTW, you don't need the `return` statement in `square`. Just call the callback. – Barmar Aug 08 '14 at 03:53

0 Answers0