Giter VIP home page Giter VIP logo

Comments (5)

adamchenwei avatar adamchenwei commented on July 20, 2024 1

@renanbastos93 thanks for the suggestion! it's really clever! Would use this to optimize the logic I currently have. Thank you so much!

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

Yes, follow the example below:

((async () => {
    const image2base64 = require('image-to-base64');
    const paths = ["path/img1.jpg", "path/img2.jpg", "path/img3.jpg"];
    
    try{
        for (let i=0; i<paths.length; i++) {
            await image2base64(paths[i])
        }
    } catch(error) {
        console.log("Some error ==> ", error)
    }

})();

Do you understand @adamchenwei ?

from image-to-base64.

adamchenwei avatar adamchenwei commented on July 20, 2024

@renanbastos93 the problem I was trying to solve is I am saving these generated base64 string into another collection of data, so I want to do something ONLY after all the base64 conversion are ended. This likely won't help with it, as it still did not really give a clear indicator of "end" of loop... or maybe I missed to read something in the code?

For now though, I am using the good old length count to determine that...

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

@adamchenwei
Okay, you can to use Promise.all, because of this code return ever a promise.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

const image2base64 = require('image-to-base64');
const paths = ["path/img1.jpg", "path/img2.jpg", "path/img3.jpg"];
const waitResolve = [];
for (let i=0; i<paths.length; i++) {
    waitResolve.push(image2base64(paths[i]));
}
Promise.all(waitResolve).then(console.log).catch(console.log);

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

@adamchenwei Did you resolved your problem?

from image-to-base64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.