Try moving the callback()
here:
function getFileSizes (callback) {
async.each(imgSources, function (img, _callback) {
gm(img).filesize(function (err, value) {
checkSize(img, value);
_callback();
});
}, function(err){ callback(err); }); /* <-- put here */
/* callback(); <-- wrong here */
},
each
accepts a callback as a third parameter that gets executed when the inner loop over each element is finished:
Arguments
arr
- An array to iterate over.iterator(item, callback)
- A function to apply to each item inarr
. The iterator is passed acallback(err)
which must be called once it has completed. If no error has occured, thecallback
should be run without arguments or with an explicitnull
argument.callback(err)
- A callback which is called when alliterator
functions have finished, or an error occurs.