I use node.js 18.9.1 on Windows.
I have a list of files (array) and need to process externally, in parallel, with a executable. After ALL processes completed, if ALL succeeded I need to go further.
Using spawn, seems that all executes in parallel (I see this in their PID) which is good.
But I just can't figure out how to wait blocking until ALL finishes and if possible, collect their result codes (to see success/error).
const promises = MyFilesArray.map(async iFile => {
const res = spawn(myExe, iFile);
res.on("close", code => {
console.log(`child process exited with code ${code}`);
});
return res;
});
async function main() {
const response = await Promise.all(promises);
console.log(response);
}
main();
console.log('done'); // this needs to be executed AFTER all async processes that run in parallel, completes !
Thanks for any hints in advance!