How can I wait for the function to return.Is there a way to wait for a function to finish executing before I continue with my code. I would like to wait for the createThumbnail function to return the buffer before I continue. Thank you.
createThumbnail: function(imagepath){
Jimp.read(imagepath).then(function (lenna) {
lenna.resize(256, 256) // resize
.quality(60) // set JPEG quality
// .greyscale() // why on earth would i need black and white
.getBuffer(Jimp.MIME_JPEG,function(err, buffer, callback){ // I have other Options like png etc.
return buffer;
})
}).catch(function (err) {
console.error(err);
});
},
and then in another file i call this function
var thum_image = functions_api.createThumbnail(Imagepath);
console.log(thum_image); // its null
callbackandPromisein JavaScript..