Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active June 25, 2023 09:12
Show Gist options
  • Save joepie91/255250eeea8b94572a03 to your computer and use it in GitHub Desktop.
Save joepie91/255250eeea8b94572a03 to your computer and use it in GitHub Desktop.
Bluebird Promise.try using ES6 Promises

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());
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment