const filesToTranslate = await getFilesToTranslate();
await Promise.all(filesToTranslate.map(async item => {
doExtraction(item)
}));
I would like to execute doExtraction every 30 seconds so the server don't choke.
Any smart to do that?
const filesToTranslate = await getFilesToTranslate();
await Promise.all(filesToTranslate.map(async item => {
doExtraction(item)
}));
I would like to execute doExtraction every 30 seconds so the server don't choke.
Any smart to do that?
You could use a timeout:
const filesToTranslate = await getFilesToTranslate();
for (const item of filesToTranslate) {
await new Promise(resolve => setTimeout(resolve, 30000));
doExtraction(item);
}
Using await inside the loop will pause the iteration until the Promise has resolved.
If you want the first doExtraction to execute immediately:
const filesToTranslate = await getFilesToTranslate();
for (const item of filesToTranslate) {
doExtraction(item);
if (filesToTranslate.Slice(-1) !== item) {
await new Promise(resolve => setTimeout(resolve, 30000));
}
}
await is being used for getFilesToTranslate().