compressorjs icon indicating copy to clipboard operation
compressorjs copied to clipboard

Is there a way to synchronize?

Open Gianna-w opened this issue 2 years ago • 1 comments

Gianna-w avatar May 13 '22 03:05 Gianna-w

What does "synchronize" mean exactly?

fengyuanchen avatar May 15 '22 03:05 fengyuanchen

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.

josuemoragl avatar Aug 26 '22 18:08 josuemoragl

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);

fengyuanchen avatar Aug 28 '22 04:08 fengyuanchen

Thanks so much for your help Fengyuanchen

josuemoragl avatar Aug 28 '22 20:08 josuemoragl