I have an array, I need to recompile with the use of some edits. I do it with the help of async.concat(), but something is not working.
Tell me, where is the mistake?
async.concat(dialogs, function(dialog, callback) {
if (dialog['viewer']['user_profile_image'] != null) {
fs.exists(IM.pathToUserImage + dialog['viewer']['user_profile_image'].replace('%s', ''), function(exits) {
if (exits) {
dialog['viewer']['user_profile_image'] = dialog['viewer']['user_profile_image'].replace('%s', '');
}
callback(dialog);
});
}
}, function() {
console.log(arguments);
});
In my opinion, everything is logical. callback is invoked immediately after the first iteration. But how can I send the data after the completion of processing the entire array?
Thank you!
Instead of callback(dialog);, you want
callback(null,dialog);
because the first parameter to the callback function is an error object. The reason that console.log(arguments) is getting called after the first iteration is because async thinks an error occurred.
I solved the problem but did not understand its meaning. The problem was due to the element which was null instead of the processed value. The program broke off at this point, but do not throw away any errors / warnings.
async.map(dialogs, function(dialog, callback) {
if (dialog['viewer']['user_profile_image'] == null) {
dialog['viewer']['user_profile_image'] = IM.pathToUserImage;
}
fs.exists(IM.pathToUserImage + dialog['viewer']['user_profile_image'].replace('%s', ''), function(exits) {
if (exits) {
dialog['viewer']['user_profile_image'] = dialog['viewer']['user_profile_image'].replace('%s', '');
}
callback(null, dialog);
});
}, function(err, rows) {
if (err) throw err;
console.log(rows);
});