In your example, the fetch function will be called three times, once for each of the file names in the array passed as the first parameter to async.map . The second callback parameter will also be passed to fetch , but this callback is provided by the async framework, and you should call it when your fetch function has completed its work, providing its results to this callback as the second parameter. The callback that you provide as the third parameter in async.map is called when all three fetch calls have called the callback provided to them.
See https://github.com/caolan/async#map
So, to answer your specific question in the code, the callback function that you provide is executed as a callback when all requests are completed. If you need to pass a fetch callback, you will do something like this:
async.map([['file1', 'file2', 'file3'], function(value, callback) { fetch(value, <your result processing callback goes here>); }, ...
Johnnyhk
source share