I'm sure this is a fairly simple task, but I'm not able to wrap my head around it at this time. I've got a nested set of forEach loops, and I need to have a callback for when all the loops are done running.
I'm open to using async.js
This is what I'm working with:
const scanFiles = function(accounts, cb) {
let dirs = ['pending', 'done', 'failed'];
let jobs = [];
accounts.forEach(function(account) {
dirs.forEach(function(dir) {
fs.readdir(account + '/' + dir, function(err, files) {
files.forEach(function(file) {
//do something
//add file to jobs array
jobs.push(file);
});
});
});
});
//return jobs array once all files have been added
cb(jobs);
}
scanFiles
returning aPromise
instead of working with callbacks? – Transceiver