Try Promise.all on batches of 16
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Amy 2022-06-04 18:07:33 -04:00
parent 1e49241a0d
commit a6bc1ec256
1 changed files with 51 additions and 47 deletions

View File

@ -46,8 +46,11 @@ export async function optimizeImages() {
const numberOfWorkers = Math.min(cpus().length, 8);
const imagePool = new ImagePool(numberOfWorkers);
const batchSize = 16;
for (let i = 0; i < imagePaths.length; i += batchSize) {
await Promise.all(
imagePaths.map(async (imagePath) => {
imagePaths.slice(i, i + batchSize).map(async (imagePath) => {
const imageStartTime = Date.now();
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
@ -104,6 +107,7 @@ export async function optimizeImages() {
);
})
);
}
await imagePool.close();