How can I wrap a function which can have sync/a-sync functionality inside with promise ?
I've call to the function like following
action[fn](req, res);
in function fn(in following example) is run can have inside (I use dynamic call for every function) sync or a-sync like below example,
- How its recommended to wrap it in promise .
- How to handle errors if any...
I use nodeJS application
run: function (req, res, filePath) {
var writeStream = fs.createWriteStream(fileRelPath, {flags: 'w'});
req.pipe(writeStream);
req.on("end", function () {
console.log("Finish to update data file")
});
res.end("File " + filePath + " saved successfully");
}