compressorjs
compressorjs copied to clipboard
Is there a way to synchronize?
What does "synchronize" mean exactly?
Hi!, I guess Giana means to in order to ingress data return the compressed data with the same order. I have the same issue, I need to compare the two images, so I get to arrays, one for the original images and the other for the compressed images. When I show the comparison, the images order in both array are different.
You can use async/await
and Promise
for that:
async function compress(image) {
return new Promise((resolve, reject) => {
new Compressor(image, {
success: resolve,
error: reject,
});
}
}
async function process(images) {
for (const image of images) {
await compress(image);
}
}
process(images);
Thanks so much for your help Fengyuanchen