Let's say I have a synchronous function like path.join()
. I want to wrap it into a Promise
because I want exceptions to be handled within catch()
block.
If I wrap it like below, I do not get an exception in the Promise
's .catch()
block. So I have to use if
to check the return value for whether it's an error or not and then call resolve
or reject
functions. Are there any other solutions?
var joinPaths = function(path1,path2) {
return new promise(function (resolve, reject) {
resolve(path.join(path1, path2));
});
};