This may have been asked before, but I couldn't find it!
I need to process a series of image files with jimp, and I'm trying to be as efficient as possible.
My current program simply uses "await jimp.read(...)" synchronously before processing it. What I'd like to do is read the images asynchronously, but here's the catch: I need to process the results in order.
At a minimum, I'm thinking I need to read the next image asynchronously while processing the current image, then (when finished processing) wait for the next image to finish being read before starting the next iteration, if that makes sense.
Is there a pattern I should use for doing this? Is there a better approach than what I describe above?
Thanks!
Edited to include a summary of my current approach:
image = await jimp.read("image_1");
for (let i = 1; i <= totalImages; i++) {
if (i < totalImages)
var imagePromise = jimp.read("image_" + (i+1));
processImage(image);
image = await imagePromise;
}
It just processes one image while reading the next, but it may need to (a)wait if the next image hasn't been completely read yet.