Note that this will only be equivalent to Promise.try
if your runtime or ES6 Promise shim correctly catches synchronous errors in Promise constructors.
If you are using the latest version of Node, this should be fine.
var Promise = require("es6-promise").Promise; | |
module.exports = function promiseTry(func) { | |
return new Promise(function(resolve, reject) { | |
resolve(func()); | |
}) | |
} |