async icon indicating copy to clipboard operation
async copied to clipboard

async.map runs through without any callback()

Open cruiser12 opened this issue 12 years ago • 3 comments

async.map([1,2,3],_runTest2, function(err, results)
{
  console.log(results);
});

function _runTest2(item,callback)
 {
   console.log(item);
}

is returning

1
2
3

And i really thought map() is waiting for any callback to proceed. What can i use to achieve a behaviour like this, that the next item is processed after a callback(null,res)

cruiser12 avatar Jul 08 '14 10:07 cruiser12

async.mapSeries() is the way to go.

cruiser12 avatar Jul 08 '14 14:07 cruiser12

You are not calling the callback in _runTest2. Since async.map is parallel, it will call _runTest2 for all the items, but then wait forever for them to call-back, meaning the main map callback will never be called.

aearly avatar Jul 08 '14 19:07 aearly

async.mapSeries() seems nice but it is so slow in my implementation. @cruiser12 did you figure out how to resolve this with async.map() ?

jzapantis avatar Apr 02 '17 23:04 jzapantis