Saturday, 15 March 2014

callback - Executing imported Javascript functions in order -


I want to execute 2 functions in a particular I have 2 others. I have imported from JS files. The function which needs to be completed first takes a little while and before the end comes the other starts and I need to first create files to work. Here basically my JS looks:

  var pdfToPng = Required ("./pdfToPng.js"); Var doStuffToPng = Required ("./ doStufftoPng.js"); Var pdfFilePath = process.argv [2]; Var pngFilePath = pdftoPng.convert (PdfFilePath); // Convert a path / and creates png and return path / / png doStuffToPng.doStuff (pngFilePath); // To start with "Convert ()" I want "DUSTF ()"  

I'm pretty sure there is something to do with callback, but I'm a JavaScript knob And need help I can get it to work with setTimeout (), but it seems like "duct tape fix" for me is there any way more beautiful?

EDIT: Some wonderful people wanted to help and asked to post it, pdfToPng.js:

  var spindrift = required ('spindrift'); // This requires a node module var fs = ('FS'); // pngfolder creates a png from pdf and gives the path to that PNG export. Conversion = function (path) {var pdf = spindrift (path); Var pathToPng = path.substring (0, path.length-4); // PDF path takes you away +++ "" _out.png "; // This is the thing for Spindrift, in it DIR PNGFoulder / PathTPNG PDF: Stream (500) .pip (fs.createWriteStream (" pngFolder / "+ pathtiping) ); "Pngfolder /" + pathToPng Return;}  

javascript Welcome to the async world. Function callback is synchronously executed asynchronously, so if you modify the code Only after performing DustFood will you know that the function has been converted to execute. How can you find it? @


No comments:

Post a Comment