I have an array of promises I try to process one after the others
function asyncInsertMagFromFile(file, resolve) {
//some asynchronous processing with file
resolve();
}
let magRequests = fs.readdirSync(storeDir).map(function(file) {
return new Promise(resolve => {
asyncInsertMagFromFile(file, resolve);
});
});
I'm trying to process these promises (magRequests) "synchronously" without success. Lot's of questions about that subject exist but I havent found one that fit with my problem. I tried some of trincot solutions here https://stackoverflow.com/a/40329190/7531001 but I don't know how to handle my file parameter.
For example this doesn't work (await is only valid in async function)
(async function loop() {
fs.readdirSync(storeDir).forEach(function(file) {
await new Promise(resolve =>
asyncInsertMagFromFile(file, resolve)
);
});
})();
Any idea how I can fix this ?