Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
This repository was archived by the owner on May 30, 2024. It is now read-only.

can't make function synchonize #52

Description

@TechGuyVN

I have a function in nodejs, some reason i want it synchonize before do another step. I research a lot but no solution working. Currently i use node-sync:

My function like this:

function downloadImageIcon(url,path,ori,callback){
    var request = require('request');
    //Sync(function() {
        request.get({url: url, encoding: 'binary'}, function (err, response, body) {
            console.log("start load: " + path);
            //Sync(function() {
                fs.writeFile( ori, body, 'binary', function (err) {
                    if (err)
                        console.log(err);
                    else {// if success then we need to convert it
                        console.log("converting : " + path);
                            fs.writeFileSync( path, imagemagick.convert({
                                srcData: fs.readFileSync(ori),
                                width: 1024,
                                height: 1024,
                                resizeStyle: 'aspectfill', // is the default, or 'aspectfit' or 'fill'
                                gravity: 'Center' // optional: position crop area when using 'aspectfill'
                            }));
                        callback();

                    }
                //});
            });
            console.log("end load: " + path);

    });
    //})
}

  1. - download image from server
  2. - store in local
  3. - convert to different resolution

Function work well but i need it to synchronize when called. Thanks for investigate!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions