Start a promise chain
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.editorconfig Meta tweaks Jul 27, 2017
.gitattributes Meta tweaks Jun 14, 2018
.gitignore Meta tweaks Jul 27, 2017
.npmrc Meta tweaks Jul 27, 2017
.travis.yml Allow passing arguments through and require Node.js 6 (#2) Jun 14, 2018
index.js Meta tweaks Jun 14, 2018
license Meta tweaks Jul 27, 2017
package.json 2.0.0 Jun 14, 2018
readme.md Meta tweaks Jun 14, 2018
test.js Meta tweaks Jun 14, 2018

readme.md

p-try Build Status

Start a promise chain

How is it useful?

Install

$ npm install p-try

Usage

const pTry = require('p-try');

pTry(() => {
	return synchronousFunctionThatMightThrow();
}).then(value => {
	console.log(value);
}).catch(error => {
	console.error(error);
});

API

pTry(fn, ...args)

Returns a Promise resolved with the value of calling fn(...args). If the function throws an error, the returned Promise will be rejected with that error.

Support for passing arguments on to the fn is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.

Related

  • p-finally - Promise#finally() ponyfill - Invoked when the promise is settled regardless of outcome
  • More…

License

MIT © Sindre Sorhus