吕君喜 406d880ac6 first | 3 anni fa | |
---|---|---|
.. | ||
index.js | 3 anni fa | |
license | 3 anni fa | |
package.json | 3 anni fa | |
readme.md | 3 anni fa |
Start a promise chain
$ npm install p-try
const pTry = require('p-try');
pTry(() => {
return synchronousFunctionThatMightThrow();
}).then(value => {
console.log(value);
}).catch(error => {
console.error(error);
});
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.
Promise#finally()
ponyfill - Invoked when the promise is settled regardless of outcomeMIT © Sindre Sorhus